Forums Forums Search & Filter Pro Querying posts by parent depending on $post->ID?

Viewing 10 posts - 1 through 10 (of 19 total)
  • Anonymous
    #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?

    Trevor
    #81105

    I would need to ask the developer, Ross, about this. I will refer it to him.

    Anonymous
    #81116

    Thank you

    Anonymous
    #81579

    Hi 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

    Trevor
    #81587

    I have sent him a message this morning to bump the thread. He has been busy getting v2.3.0 released (finished and released last night).

    Ross Moderator
    #81650
    This reply has been marked as private.
    Anonymous
    #82027

    Hi 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
    #82032

    Hey 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
    #82155
    This reply has been marked as private.
    Anonymous
    #83156

    Hi 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

Viewing 10 posts - 1 through 10 (of 19 total)