• Resolved handiworknyc

    (@handiworknyc)


    Depending on my post type, I’m using different custom fields for the excerpt. In the code below $thecontent is what’s showing for the excerpt in my search results template. I’m using this in tandem with search filter pro.

    So the below code is for a search filter pro search. But I would like to use relevansi’s custom generated excerpt when there is a search string present… in the context of search filter pro, that’s the _sf_s query string.

    How can I use Relevanssi’s custom excerpt in this case? I’ve looked at this page: https://www.relevanssi.com/user-manual/filter-hooks/relevanssi_excerpt_part/ … but it’s not clear how to use it in this context.

    			$thecontent = get_post_meta($postid,'intro_text', true);
    			
    			if(empty($thecontent)) {
    				$thecontent = get_the_excerpt($postid); 		
    
    				$cust_excerpt = trim(get_post_meta($postid,'cust_excerpt', true));
    				
    				if(!empty($cust_excerpt)) {
    					$thecontent = $cust_excerpt;
    				}
    			}
    
    			if($posttype == 'people' && empty($thecontent)) {
    				$thecontent = get_post_meta($postid,'automated_bio', true);
    					$thecontent = strip_tags($thecontent);
    					$thecontent = trim($thecontent);
    			}
    			
    			if($posttype == 'calendar_event') {	
    				
    				$location = get_post_meta($postid,'event_location', true);
    				$address = explode( ',' , $location['address']);
    				
    				$theaddress = '';
    				
    				if(!empty($address)) {
    					$theaddress .= $address[0].'<br/>'; //place name
    					$theaddress .= $address[1].'<br/>'; // street address
    					$theaddress .= $address[2].','.$address[3]; // city, state zip_close()
    					$theaddresslink = 'https://www.google.com/maps?saddr=My+Location&daddr=' . $location['lat'] . ',' . $location['lng'];		
    				} else {
    					$theaddress .= get_post_meta($postid,'event_address', true);
    					$theaddresslink = strip_tags($theaddress);
    				}
    				$thecontent = '<a href="' . $theaddresslink . '" class="lib-card--address icon-map-marker">' . $theaddress . '</a>';
    				
    			} elseif( !empty($thecontent) ) {
    				$thecontent = apply_filters( 'the_content', $thecontent );
    				$thecontent = preg_replace("/<img[^>]+\>/i", "", $thecontent);
    
    ... 
    ...

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Mikko Saari

    (@msaari)

    If you’ve checked the box to have Relevanssi create custom excerpts for you, $thecontent = get_the_excerpt($postid); should contain the Relevanssi excerpt. If not, and it’s possible S&F Pro interferes with this, you can try something like this:

    global $wp_query;
    if ( ! empty( $wp_query->query_vars['_sf_s'] ) ) {
      $thecontent = relevanssi_do_excerpt( $postid, $wp_query->query_vars['_sf_s'] );
    }
    Thread Starter handiworknyc

    (@handiworknyc)

    Thanks so much for the quick response!!

    this “worked” in that it echoed out something… but it just echoed “content” on all the posts

    I do have the custom excerpt setting checked in the back-end.

    		if ( ! empty( $_GET['_sf_s'] ) ) {
    			$thecontent = relevanssi_do_excerpt( $postid, $_GET['_sf_s'] );
    		}
    Thread Starter handiworknyc

    (@handiworknyc)

    That first argument needed to be post object, not post id. and it worked!

    Plugin Author Mikko Saari

    (@msaari)

    Yeah, sorry about that, my bad.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to use custom excerpt’ is closed to new replies.