Reply To: filter content results

#2537

Ernest Marcinko
Keymaster

Hi!

It's not exactly like that. The $allpageposts variable holds an array() of objects, and each object is one result.
Here is a quick snippet I had just written, it takes all the categories from a post and appends it to the end of the post title:

add_filter( 'asp_pagepost_results', 'my_results_modify', 1, 1 );

function my_results_modify( $pageposts ) {
  foreach ($pageposts as $k=>$v) {
  
    /** The structure is:
        object(stdClass) {
          ["title"]     => "Post title"     
          ["id"]        =>  1234
          ["date"]      => "2014-08-06 12:48:19"
          ["content"]   => "Post content
          ["author"]    => "author"
          ["post_type"] => "post"
          ["image"]     => "http://..."
          ["link"]      => "http://..."
        }
     */ 
     
    // Get the post categories 
    $post_categories = wp_get_post_categories( $pageposts[$k]->id );
    $cats = "";
    
    // Concatenate category names to the $cats variable	
    foreach($post_categories as $c){
    	$cat = get_category( $c );
    	$cats = " ".$cat->name;
    }                 
  
    // Modify the post title
    $pageposts[$k]->title  .= " ".$cats;
  }
  
  return $pageposts;
} 

I've also added the structure in the commented section, so you can see which variables you can access and change.

Best,
Ernest Marcinko

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