Forums › Forums › Search & Filter Pro › Querying posts by parent depending on $post->ID?
Tagged: $query_args, query results, sf_edit_query_args
- This topic has 18 replies, 3 voices, and was last updated 7 years, 10 months ago by Anonymous.
-
Anonymous(Private) January 10, 2017 at 12:07 pm #81092
Hi,
I’m trying to display posts related to their parent using just one search form. I’ve been trying to do this by using the
sf_edit_query_args
filter you have in your documentation but it’s only working when first visit the page. Once you start searching it defaults back to showing all the posts.I’m using the shortcode to display in a single custom post type template with AJAX enabled.
Here’s what i have:
function filter_function_name( $query_args, $sfid ) { global $post; if($sfid==42) { if($post->ID == 54) { $query_args = array ( 'post_parent__in' => array('54'), ); } else if($post->ID == 5) { $query_args = array ( 'post_parent__in' => array('5'), ); } } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 10, 2 );
It works if i remove the if statements from within if($sfid==42) {. For example if this works:
function filter_function_name( $query_args, $sfid ) { global $post; if($sfid==42) { $query_args = array ( 'post_parent__in' => array('54'), ); } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 10, 2 );
Are you able to help me?
Anonymous(Private) January 12, 2017 at 9:58 am #81579Hi Trevor,
Have you been able to forward this message to the developer yet?
I have realised there is another method i could try to achieve what i want but this would require to create multiple search forms and then target their IDs individually using the sf_edit_query_args function.
I understand the developer is a busy man and i don’t want to be a pest but are you able to give an estimated time for when you think he’ll get a chance to look at it?
This is for a project i’m working on for a client in which the deadline is at the end of the month so if the waiting list is long then i don’t mind going for the alternative method.
Many thanks
Anonymous(Private) January 13, 2017 at 11:30 am #82027Hi Ross,
Thanks for getting back to me on this.
Unfortunately i can’t share a link to the site at the moment as i’m working on it locally but i will try and upload it live somewhere today so you can have a look at it.
And yes, it displays the posts associated with the $post->ID correctly when you first go to the page and also shows the search options for just those posts. It’s when i make a search it then defaults back to all posts 🙁
However, if i don’t include an if statement and just use the code below it then shows the posts under the $post->ID 54.
function filter_function_name( $query_args, $sfid ) { global $post; if($sfid==42) { $query_args = array ( 'post_parent__in' => array('54'), ); } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 10, 2 );
Ross Moderator(Private) January 13, 2017 at 11:51 am #82032Hey Shaun
Will await your update with a live link (it would be handy to have temp admin access too).
Also, we released an update to the plugin yesterday, can you update that too, there were quite a few bug fixes hoping there is some overlap with your issue.
Best
Anonymous(Private) January 17, 2017 at 4:13 pm #83156Hi Ross,
Did you manage to have a look at this?
I went back into the site today and it’s not working again. I think it may have something to do with the cache but no entirely sure.
If you could check it out and let me know what you think that’d be great.
Many thanks,
Shaun -
AuthorPosts