This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

filter content results

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #2476
    daviddavid
    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
    daviddavid
    Participant

    up ?

    #2537
    Ernest MarcinkoErnest 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.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.