filter content results

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

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #2476
    david
    david
    Participant

    Hi there 🙂
    so to filter the results, how should I do ?
    right now, the structure of each result is something like :
    the title etc…

    So what’s the filter…something like :
    $allpageposts = apply_filters( ‘asp_pagepost_results’, $allpageposts );

    where
    $allpageposts = “the_title(); the_excerpt(); customFunctions();”

    it should work ?

    Thank you in advance

    #2535
    david
    david
    Participant

    up ?

    #2537
    Ernest Marcinko
    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 :)


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

You must be logged in to reply to this topic.