Support » Fixing WordPress » use query_posts get posts by multiple custom fields

  • Resolved hermitjim

    (@hermitjim)


    Hi, I’ve hunted for an answer to this and haven’t found one that works. Trying to make sense of someone-else’s code. I’m trying to show posts by author ID, post type=private, and two custom fields ‘paid_user’ and ‘txrole’. The code below is just returning all private posts from all users, and not differentiating between the custom fields. What am I doing wrong? Thank you for your help.

    <?php
    
    	global $wp_query;
    	$query_vars = $wp_query->query_vars;
    	$post_per_page = 20; 
    
    	global $current_user;
    	get_currentuserinfo();
    	$uid = $current_user->ID;
    
    	$winner = array(
    	'meta_key' => 'winner',
    	'value' => $uid,
    	'compare' => '='
    	);
    
    	$paid = array(
    	'meta_key' => 'paid_user',
    	'value' => "0",
    	'compare' => '='
    	); 
    
    	$tx_role = array(
    	'meta_key' => 'txrole',
    	'value' => "bought",
    	'compare' => '='
    	); 
    
    	$args = array(
    	'post_status' => 'private',
    	'post_author'=>$uid,
    	'order' => 'DESC',
    	'orderby' => 'date',
    	'posts_per_page' => $post_per_page,
    	'pages' => $query_vars['paged'],
    	'meta_query' => array($winner, $paid, $tx_role));
    
    	query_posts($args);
    
    	if(have_posts()) :
    		while(have_posts()) : the_post();
    			get_backoffice();
    		endwhile;
    
    		if(function_exists('wp_pagenavi')): wp_pagenavi(); endif;
    	else: _e("None",'AuctionTheme');
    
    	endif;
    
    	wp_reset_query();
    ?>

    PS – get_backoffice() is just a function to format the results, which is working fine elsewhere.

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘use query_posts get posts by multiple custom fields’ is closed to new replies.