Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I’ve got a metabox I set up using WPAlchemy that allows authors to add a link to an associated post. It’s been working fine for months but now for some reason the dropdown with the appropriate posts isn’t updating. Here’s the code in the custom post meta php file:

<p>

<?php $mb->the_field(‘product_video_ID’); ?>
<select name=”<?php $mb->the_name(); ?>”>
<option value=”">None</option>

<?php

global $thispost;
$myposts = get_posts(‘numberposts=5000&offset=1′);

foreach($myposts as $thispost) :
if (in_category(“Product Videos”, $thispost)) {
?>
<option value=”<?php echo $thispost->ID; ?>” <?php $mb->the_select_state($thispost->ID);?> ><?php echo get_the_title($thispost->ID); ?></option>

<?php } ?>

<?php endforeach; ?>
<?php setup_postdata($thispost);?>
</select>
</p>

I tried adding a couple test posts in the Product Videos category and they didn’t show, either. I commented the lines that filtered for that category and the Meta box dropdown updated to show every post… except the one I wanted and the new test ones. Anybody have any idea what might be going on? Is there some part of the machinery here that isn’t updating that I should fix? Thanks so much!

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Try WP_Query to get the posts, since get_posts() also makes use of it:

$args = array(
    'category_name' => 'product-videos',
    'posts_per_page' => 5000, // or -1 if you want all
    'offset' => 1
);

$the_query = new WP_Query( $args );

if ( $the_query->have_posts() ) :
    while ( $the_query->have_posts() ):
        $the_query->the_post();
        ?>
        <option value=”<?php the_ID(); ?>” <?php $mb->the_select_state(get_the_ID());?> ><?php echo get_the_title(get_the_ID()); ?></option>
        <?php
    endwhile;
endif;
share|improve this answer
    
Thanks - using WP_Query ended up causing all sorts of bugs, but you also hit the nail on the head on the issue - I was querying only 5000 posts, and the issue started because the site had surpassed 5000 so the new ones weren't showing. Simply changing 5000 in my code to -1 fixed the issue :-) –  James Morrison Apr 23 '13 at 20:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.