WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Querying two custom fields in custom post type.. (3 posts)

  1. Esquivelia
    Member
    Posted 12 months ago #

    Ok so I can get it to work with querying one custom field but when I try two it doesn't work like I would think it would.

    Here is my code:

    <?php
    	$args = array( 'post_type' => 'ait-dir-item',
    	               'meta_key' => 'location',
    	               'meta_value' => 'Annapolis',
    	               'meta_key' => 'item_tags',
    	               'meta_value' => 'Non-Marine',
    	               'posts_per_page' => 300 );
    	$loop = new WP_Query( $args );
    	while ( $loop->have_posts() ) : $loop->the_post();
    		the_title('<h3 class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h3>');
    		echo '<div class="entry-content">';
    		the_content();
    		echo '</div>';
    	endwhile;
    ?>

    Thanks in advance!

    Cory-

  2. Esquivelia
    Member
    Posted 12 months ago #

    anyone?

  3. Esquivelia
    Member
    Posted 12 months ago #

    Ok answered my own question.. :)

    <?php
    	$args = array( 'post_type' => 'ait-dir-item',
    	               'meta_query' => array(
    				        array(
    				            'key' => 'location',
    				            'value' => 'annapolis'
    				        ),
    				        array(
    				            'key' => 'item_tags',
    				            'value' => 'non-marine'
    				        )
    				    ),
    				   	'orderby' => 'title',
    					'order' => 'ASC',
    	               'posts_per_page' => 300 );
    	$loop = new WP_Query( $args );
    	while ( $loop->have_posts() ) : $loop->the_post();
    		the_title('<h3 class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h3>');
    		echo '<div class="entry-content">';
    		the_content();
    		echo '</div>';
    	endwhile;
    ?>

Reply

You must log in to post.

About this Topic