Problems with excerpt "Read more" link on search results page

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Problems with excerpt "Read more" link on search results page

This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 6 years, 11 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #12883
    bethblinebury
    bethblinebury
    Participant

    This is a multisite system. I am using one search called “Sitewide Search” and I have opted to “Override the default WordPress search results” so that all of my multisite results appear.

    The titles properly link, but there is a problem with the “Read More” button generated by the excerpt. It does not print anything in the href for the link. The function I’m using is the super standard WP excerpt hook:

    
    function new_excerpt_more( $more ) { // customize excerpt on blog & search results
    	return '... &lt;div class="button minimal"&gt;<a href="'. get_permalink(get_the_ID()) . '">' . __('Read More', 'your-text-domain') . '</a>&lt;/div&gt;';
    }
    add_filter( 'excerpt_more', 'new_excerpt_more' );
    

    The excerpt works properly when I use the default search results, but the whole point is that I want to return the multisite results.

    Let me know what you think! My search is also pretty basic. I figure I could load & trim the content on the search results page if I have to, but I’d prefer to just use the_excerpt.

    FYI, I’m hosted on WP Engine which uses SFTP and port 2222.

    Thanks,
    Beth

    #12896
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Beth,

    The code is indeed very standard and widely used, however problems arise from a different source. Basically WordPress is not capable of displaying results from sites other than the current – as the posts are stored in separate databases and IDs will collide.

    I have however found a solution which works in 99% of the cases, so whenever the search override is enabled it tries to force the correct URL if possible, for cross-site results as well. However it appears that it simply won’t work with the custom code you have, and it seems like it will not, unles that code is changed a bit.

    So, I have made the following change to that code:

    function new_excerpt_more( $more ) { // customize excerpt on blog & search results
    	global $post;
    	$url = isset($post->asp_guid) ? $post->asp_guid : get_permalink(get_the_ID());
    	return '... <div class="button minimal"><a class="learnmore" href="'. $url . '">' . __('Read More', 'your-text-domain') . '</a></div>';
    }
    add_filter( 'excerpt_more', 'new_excerpt_more' );

    The difference is that this one will try to check if the URL stored by the search in the post object still exists, and if so, then uses that. So far it looks like it’s working, but please let me know if that is not the case.

    Best,
    Ernest Marcinko

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


    #12899
    bethblinebury
    bethblinebury
    Participant

    Hi Ernest,

    Yes this updated code does seem to have worked its magic! I tested it out and we’re good to go.

    Thanks so much for your prompt reply and solution! The plugin is great.

    Beth

    #12900
    Ernest Marcinko
    Ernest Marcinko
    Keymaster
    You cannot access this content. Best,
    Ernest Marcinko

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


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

You must be logged in to reply to this topic.