- This topic has 16 replies, 4 voices, and was last updated 6 years ago by Leo.
-
AuthorPosts
-
January 16, 2018 at 9:28 am #472403Alberto
Hello!
I’m trying to get something like what Otto stated here but in my case I don’t use Elementor, just GP Pro.
I want to display the results as standard posts, i.e., as you are displaying the posts here at https://generatepress.com/support/
The results can be from an event, company data or a news entry (all of these CPT), so I would like to show, along with the word(s) searched, the category or type of post in which it appears.I’ll appreciate any help.
Thanks in advance.
January 16, 2018 at 8:07 pm #472876TomLead DeveloperLead DeveloperHi there,
Our support forum is using bbPress, so it’s not the regular post loop.
Can you show me an example of the layout you’re wanting to achieve?
January 17, 2018 at 5:07 am #473104AlbertoHello Tom.
It’s really something basic, I think.
You can see an image of what I’m trying to get here: https://prnt.sc/i1o8zx
I want to show only the title of the post and the section it is in, with a link to the post.
No problem with the post in Nieuws or in Standhouders, but the information I enter in Spreker (a CPT) is showed in a sidebar of Programma’s page (see here: http://duitslanddag.nl/de-sprekers) so I want to link the last entry (showed in image) to the event page and not to the spreker page, i.e., http://duitslanddag.nl/events/duitslandervaring-jaap-schalken/ and not http://duitslanddag.nl/spreker/jaap-schalken/What are the files I’ve got to edit and how can I achieve this?
Thanks in advance!
Alberto.
January 17, 2018 at 5:15 am #473108AlbertoBTW, using a plugin like Search Everything I get Sprekers or Standhouders in the results because it let me serach in custom fields or custom taxonomies, but I would like to use the search tools provided by WP (are the one you use in GP, isn’t it?) How can I do to include custom fields and taxonomies in the results with GP Search tool?
Thanks!
January 17, 2018 at 9:46 pm #473775TomLead DeveloperLead DeveloperYou could get close using CSS like this:
.search-results article { float: none !important; width: 100%; } .search-results .entry-summary, .search-results .read-more-container { display: none; }
However that won’t show the category next to the title. You could turn it on like this:
add_filter( 'generate_show_categories', 'tu_search_results_categories' ); function tu_search_results_categories( $cats ) { if ( is_search() ) { return true; } return $cats; }
Then you’d need some more CSS – let me know if you need help with it 🙂
January 19, 2018 at 1:33 am #474696AlbertoHello Tom!
The CSS code works but it doesn’t the filter.
Besides, it only displays the posts in Nieuws, not in Standhouders neither Sprekers/Programma (these are Custom Post Types).Any thoughts?
Thanks in advance!
January 19, 2018 at 2:09 am #474712AlbertoI was trying to do the search also with CPT (and Custom Fields!) with something like this, but it didn’t works.
function dom_cpt_search( $query ) { if ( is_search() && $query->is_main_query() && $query->get( 's' ) ) { $query->set( 'post_type', array('post', 'page', 'product'), 'meta_query', array( array( 'key' => 'wysiwyg', 'value' => '%s', 'compare' => 'LIKE', ), ) ); return $query; } } add_action( 'pre_get_posts', 'dom_cpt_search' );
Am I on the right track?
January 19, 2018 at 10:21 am #475105TomLead DeveloperLead DeveloperCan you link me to an example search results page? That filter should work.
That function looks right, the only part I’m not sure about is the
meta_query
parameter. What’s the%s
value you’re trying to compare with?January 23, 2018 at 5:42 am #477910AlbertoHello Tom.
Sorry for taking so long to reply.
Yes, you can take a look at: http://duitslanddag.sjbdixital.net/
If you search “duitse” you can see posts in Nieuws and even in the first result that belongs to a custom tax (category in a CPT), but no results that matches custom fields like Sprekers (see Alberto PM: Xestor Duitse) or Standhouders, another CPT (see Empresa A: Description field).Your filter is in functions.php file.
Mmmm about the function above… I found that pice of code in https://wordpress.stackexchange.com Yes, I think there’s an error there. I think it must be the search term, something like
$search_term = $query->query_vars['s'];
but I can’t get it working. Any ideas?Thanks in advance!
January 23, 2018 at 11:31 pm #478566TomLead DeveloperLead DeveloperJust to confirm here – you’re wanting the search results page to include posts from your custom post types, correct?
If so, this should be all that’s needed: https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts#Include_Custom_Post_Types_in_Search_Results
March 29, 2018 at 5:17 pm #535699JohnBeen reading over the details on customizing the search results page. I have a need where I would like to remove the Featured Image graphic from my search results. Is there a way to accomplish this in CSS?
John
March 29, 2018 at 5:20 pm #535702JohnOr. Another option in the search results that might be handy is to have the featured image shown with text beside the image, as opposed to under the image.
March 29, 2018 at 9:11 pm #535791LeoStaffCustomer SupportTry this PHP snippet:
add_filter( 'option_generate_blog_settings','lh_remove_search_featured_image' ); function lh_remove_search_featured_image( $options ) { if ( is_search() ) { $options[ 'post_image_position' ] = ''; } return $options; }
Adding PHP: https://docs.generatepress.com/article/adding-php/
March 30, 2018 at 6:11 am #536092JohnHi Leo.
Thanks for the note. I gave the snippet a try, using the Snippets plugin. I do not see any impact on the search results page (image is still present).John
March 30, 2018 at 9:12 am #536320LeoStaffCustomer SupportAhh try this instead:
add_filter( 'option_generate_blog_settings', 'lh_remove_search_featured_image' ); function lh_remove_search_featured_image( $options ) { if ( is_search() ) { $options['post_image'] = false; } return $options; }
-
AuthorPosts
- You must be logged in to reply to this topic.