So this is my Query. where category 17 is, I want this to by dynamic based on the page you're on. So I have a custom meta field called city_name but when I just put that in there. it obviously doesnt work. How do I get the 'cat' to show the custom meta name
// WP_Query arguments
$args = array (
'post_type' => 'advertisement',
'category_name' => 'city_name',
'posts_per_page' => '2',
'order' => 'DESC',
'orderby' => 'date',
);
// The Query
$search_ads = new WP_Query( $args );
// The Loop
if ( $search_ads->have_posts() ) {
while ( $search_ads->have_posts() ) {
$search_ads->the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php }
} else {
// no posts found
}
EDIT:
I started doing this:
$key_1_value = get_post_meta( get_the_ID(), 'city_name', true );
// WP_Query arguments
$args = array (
'post_type' => 'advertisement',
'category_name' => '$key_1_value',
doesn't seem to work. If I make category name "toronto" which is the "city_name" I am looking for, it works perfect. Just need that city_name to be drawn dynamically..
EDIT PROBLEM SOLVED.
ok so this turned out to be almost perfect. however, you have to reset the query, before drawing the value. Good thing it didn't take me 100 billion hours to figure out. Thanks India.
wp_reset_query
Add the reset right after the $key_value line before the arguements, then you can draw your custom meta field into the arguments.