• Resolved bridgemanusa

    (@bridgemanusa)


    Hi All:

    I am having a bit of a challenge trying to determine how to query my posts based on a meta value. I am using Flutter (tied to Post category for “Jobs”, catid=11) and created a write panel for job openings and one of the select values is the “city”. Using the menu feature in WP 3.0 I created a side menu with static links (titled by city) that point to my page template as follows:

    http://my-wp-site.com/about-us/careers/current-openings.html?city=Atlanta

    Ideally I would like to create a slew of menu items that each pass a variable (?city) to my page template and then use that value to query the meta data for the post to list only the posts for that city. I am using the following code to grab all posts and it works fine but for the life of me cannot figure out the syntax to get only the values from the meta data to list only for the requesting city.

    <h2><?php echo $city; ?></h2>
    				<ul style="list-style-type:none;">
       			   	<?php query_posts('cat=11&posts_per_page=10&order=DESC');?>
    				<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
                    <div>
    
    <li><p><h3><a>?postID=<?php the_ID(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3></p>
        			</div>
        			 <?php endwhile; else: ?>

    Any insight would be extremely helpful. Thanks in advance for looking!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Assuming the meta_key is ‘city’, this should work:

    <?php query_posts('cat=11&posts_per_page=10&order=DESC&meta_key=city&meta_value='.$city);?>

    Thread Starter bridgemanusa

    (@bridgemanusa)

    Perfect!!! That was exactly what I was looking for. Thanks for your help vtxyzzy. btw.. I like your gravitar! Is that the “Camper” model? I recently lost mine and got the Trekker to replace it.

    Thanks again!

    Glad it worked! Now, please use the dropdown at top right to mark this topic ‘Resolved’ so that others with the same problem can see that there is a solution.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘query results by get_post_meta value’ is closed to new replies.