如果zipcode值相同,我将尝试获取一个帖子列表。提前感谢您的帮助。
<?php
$query = new WP_Query( array(
\'post_type\'=> array(\'service\'),
\'posts_per_page\' => -1,
\'meta_query\' => array( array(
\'key\'=> \'zipcode\',
\'value\'=> \',\'.$zip.\',\',
\'compare\'=> \'LIKE\'
) )
));
?>
<?php if ( $query->have_posts() ) : ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<h3><?php the_title(); ?> </h3>
<?php endwhile; // end of the loop. ?>
<?php wp_reset_query(); ?>
<?php else: ?>
No results found.
<?php endif; ?>
SO网友:Praveen
以下代码适用于元查询。
$query_args = array(
\'post_type\' => \'service\',
\'posts_per_page\' => -1,
\'meta_query\' => array(
array(
\'value\' => $zip,
\'compare\' => \'LIKE\',
\'key\' => \'zipcode\',
),
)
);
$query = new WP_Query($query_args);
<?php if ( $query->have_posts() ) :while ( $query->have_posts() ) : $query->the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php endwhile; // end of the loop. ?>
<?php wp_reset_query(); ?>
<?php else: ?>
No results found.
<?php endif; ?>
希望有帮助。
SO网友:Tanmay Patel
此代码可以帮助您获得完美的结果。
<?php
$query_args = array(
\'post_type\' => \'service\',
\'posts_per_page\' => -1,
\'meta_query\' => array(
array(
\'key\'=> \'zipcode\',
\'value\'=> $zip,
\'type\' => \'numeric\',
\'compare\'=> \'=\',
),
)
);
$query = new WP_Query($query_args);
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php endwhile;
wp_reset_query();
else: ?>
<h3>No results found.</h3>
<?php endif; ?>