Support Forum

Please login to receive premium support.

Support for the free plugin can be found here.

Forum Replies Created

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • in reply to: Filter and hook overview #24991
    Theo
    Participant

    Hi Elvin,

    Thanks! I’ll take a look at the code.

    Regards,

    Theo

    in reply to: Query on more than one meta key or meta key with array value #23937
    Theo
    Participant

    Thanks, Tom!

    in reply to: Query on more than one meta key or meta key with array value #23792
    Theo
    Participant

    I created a custom taxonomy and some post meta values, stored in the database. They are used for a taxonomy filter I am working on. The values are related to a custom post type (advertisement). When the user selects the filter option(s), a form is submitted (method is post, no ajax). I’m fetching the post variables in the filter via a function call.

    As said, your suggestion works fine and with the filter I can achieve what I want, but I have the feeling that it’s a makeshift solution I’ve created😉.

    Regards,

    Theo

    in reply to: Query on more than one meta key or meta key with array value #23764
    Theo
    Participant

    Hello Tom,

    Based on your suggestions, I’ve created a filter (see below, sorry for the lengty code here), and it works fine! Still some additions to make, though. E.g. I don’t like the way I’m passing variables right now. Via a function inside the filter I collect some $_POST data, but I can’t find onother a way to pass variables to the filter. As far as I know that’s not possible, or am I overlooking something? I’m a bit reluctant to pass global variables.

    // Filter query arguments for WP Show Posts 
    add_filter( 'wpsp_query_args', function( $args, $settings ) {
    	
    	// Declare variables
    	
    	$bd_location_key = $bd_location_value = '';
    	$bd_filter_data = [];
    
    	// Get location data ( passed via $_POST and already sanitized/escaped ) 
    	
    	$bd_filter_data = bd_get_location_post();
    	
    	// Assign location data to variables
    	// Because not all location data have to be passed, 
    	// we start at the top level (country), down to the most detailled level (city)
    	// Descending order: Country -> State -> County - City
    	
    	[ ... in my script, here are the conditionals tot assign value to $bd_location_key
    	and $bd_location_value. I've skipped them here ... ]
    
    	// Add query arguments to WP Show Posts
    	// Also create a custom order clause, so we can filter on
    	// the avarage rating, stored in post meta
    	
    	if ( 97 === (int) $settings[ 'list_id' ] ) {
    		$args[ 'meta_query' ] = array(
    			array(
    				'key'     	=> $bd_location_key,
    				'value'   	=> array_shift( $bd_location_value ),
    				'compare' 	=> 'LIKE',
    				'orderby' 	=> 'meta_value',
    				'order'   	=> 'ASC',										
    			),
    			'bd_rating_order_clause' => array(
    				'key'		=> 'bd_post_average_rating'
    			),
    		);
    		
    		$args[ 'orderby' ] = array(
    			'bd_rating_order_clause' => 'DESC'				
    		);
    	}
    
    	return $args;
    
    }, 10, 2 );

    I have added an extra argument to the filter and changed the number of arguments to 3, but that throws an error.

    in reply to: Query on more than one meta key or meta key with array value #23554
    Theo
    Participant

    Hi Tom,

    Thank you for your quick reply! I’ll give it a try and let you know.

    Great that the new version of WPSP supports filtering queries! It makes this already great plugin so much more flexible…

    Regards,

    Theo

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