Custom post types not showing summaries in live search or custom results page

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Custom post types not showing summaries in live search or custom results page

This topic contains 2 replies, has 2 voices, and was last updated by patricia.clemente patricia.clemente 2 years, 1 month ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #36968
    patricia.clemente
    patricia.clemente
    Participant

    Hi,

    Additional to pages and posts, my search forms also index a custom post type, as well as event objects that have been queried directly from our database. For context, I have also created a custom results page with Elementor (utilising the ‘Posts’ widget) using the following documentation: https://documentation.ajaxsearchpro.com/elementor-integration/custom-results-page-with-elementor-pro. The post type result fields are also configured such that the primary description field is extracted from the Post Excerpt, with the secondary extracted from Post Content.

    My problem at the moment is that when searching for a custom post type, the description is only shown in the custom results page and not in the live search (see attached ‘Live Search – CPT’ and ‘Custom Search Results – CPT’), but when searching for an event from the database – the description is only shown in the live search and not the custom results page (see attached ‘Live Search – Database Object’ and ‘Custom Search Results – Database Object’). Note, some of the description text have been hidden for privacy reasons.

    The custom post type is set up with a custom field ‘summary’ which is appended to the post content using the following method:

    add_filter ( 'the_content', function( $content) {
    	$custom_field = get_post_meta( get_the_ID(), 'summary', true);
    	return $content . $custom_field;
    } );

    On the other hand, the event objects are set up using the asp_results hook – where we query events from our database and append it to $results if certain event fields contain the search terms. Given the matching event objects, we set $result->content to equal the summary field for events.

    I was wondering if I’m able to get some help so that the descriptions for the custom post type and event objects are displayed on both the live search and custom results page. Please also let me know if you need me to provide more information about this issue.

    Thank you in advance.

    Attachments:
    You must be logged in to view attached files.
    #36986
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Thank you for the details, it helps us a lot!

    To show custom field contents within the live search content fields, you can use the advanced title and content fields feature. That should take care of that.

    The results page is a different story, the plugin can not change the texts there. You may need to add a different hook for that. I believe the results page usually shows the excerpt by default, instead of the content. Maybe applying your custom code to the the_excerpt hook may simply do the trick.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #37048
    patricia.clemente
    patricia.clemente
    Participant

    Thanks for your help Ernest!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.