?
Solved

Loop the latest post-type that has a meta box checked only

Posted on 2012-08-16
1
Medium Priority
?
630 Views
Last Modified: 2012-08-16
I need to loop only 1 of the latest post-type post in my sidebar, however, I only want to loop the latest one that has a meta box checked. I use the metabox option to give the post-type two different looks (videos or photos).
I want to loop the photo type only and the problem is that if a video version of that post-type is the newest one, then it blows out the older one and displays nothing. Is there a way to do this by effecting the query arguments or something?

Here is what I have so far:

<?php $args = array( 'post_type' => 'my_post_type', '', 'posts_per_page' => -1 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php   if(get_post_meta($post->ID, 'my_post_type', true)) : ?>	
<?php the_title(); ?>
<?php endif; ?>
<?php endwhile; ?>

Open in new window

0
Comment
Question by:adrian7474
1 Comment
 

Accepted Solution

by:
adrian7474 earned 0 total points
ID: 38302632
I got it. Answered my own question. I added this to the arguments:

$args = array( 'post_type' => 'my_post_type', 'meta_key' => 'my_meta_key', 'true', 'posts_per_page' => 1 );

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
Suggested Courses
Course of the Month17 days, 9 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question