• Hi guys, this is what I want to achieve – but I have no clue how to manage to do this dynamically.

    1. get the meta values of all keys of a specific metabox where the meta value is = 1
    or get all the meta values of meta keys that start with “prodcat_” where the meta value is = 1 (I have no idea which is easier/works at all)
    2. pass the associated meta keys into individual variables (e.g. $prodcat)
    3. which can then be used to feed a custom query to define the posts listed on a page (see below)

    // The Query
    $args = array(
    	'post_type'=> 'page',
    	'post_status'=> 'publish',
    	'meta_query' => array(
    			//'relation' => 'OR',
    			array(
    				'key' => $prodcat1,
    				'value' => 1
    			),
    			array(
    				'key' => $prodcat2,
    				'value' => 1
    			),
    			array(
    				'key' => $prodcat3,
    				'value' => 1
    			),
    			// and so on, depending on the number of results
    	),
    	'orderby'=> 'title',
    	'order'    => 'ASC'
    );
    query_posts( $args );

The topic ‘Dynamically pass meta_key variables into query_posts’ is closed to new replies.