Home Forums General Issues Query Posts By Custom Field Value Not Working


Query Posts By Custom Field Value Not Working

  • I am able to query by meta_key but when I introduce the meta_value then nothing shows in the query.

    The following code works:

    	$listingPages = get_posts( 
            'meta_key' => 'select_attorney_type',
            'post_type' => 'page',
            'post_status' => 'publish',
            'orderby' => 'menu_order',
            'order' => 'ASC',
    	'posts_per_page' => '20',
    	'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
    	foreach( $listingPages as $page ) {		
    		$content = $page->post_content;
    		if ( ! $content ) // Check for empty page
    		$content = apply_filters( 'the_content', $content );
    		<div class="attyrow">
    		<div class="attycol1">
    		<a href="<?php echo get_page_link( $page->ID ); ?>"><?php echo get_the_post_thumbnail($page->ID, 'thumbnail'); ?></a>
    		<div class="attycol2">
    		<h2><a href="<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a></h2>
    		<div class="attycol3">
    		<h3><?php $key="Location"; echo get_post_meta($page->ID, $key, true); ?></h3>
    		<div class="attycol4">
    		<h3><?php $key="Type"; echo get_post_meta($page->ID, $key, true); ?></h3>
    		<div class="attycol5">
    		<h4><?php echo get_the_term_list( $page->ID, 'areas', '', ', ', '' ); ?></h4>
    		<div style="clear:both"></div>

    When I add 'meta_value' => 'Partner',

    Then the page query comes back blank.

    I’ve tried my way and the suggested way in the documentation with no luck. Any help?

  • There’s something fishy going on right now, and we’re having some straaange issues over here as well.

    Try adjusting your meta_key value to field_select_attorney_type and see what happens.

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

The topic ‘Query Posts By Custom Field Value Not Working’ is closed to new replies.