Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › filter content results
This topic contains 2 replies, has 2 voices, and was last updated by Ernest Marcinko 9 years, 11 months ago.
- AuthorPosts
- September 17, 2014 at 4:20 pm #2476
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
September 26, 2014 at 9:00 am #2535up ?
September 26, 2014 at 10:15 am #2537Hi!
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 :)
- AuthorPosts
You must be logged in to reply to this topic.