WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is really weird. I made a posttype ' mediagallery ' via the plugin Types fields. I simply want to load the post content and switch the posts with a next & prev button in de sidebar.

The post content loads correct. But when i go to the next or prev post, the content stays the same. But only the permalink does changes. All posts are refering to the same post?

This is the code example:

$args = array( 'posts_per_page' => 1, 'post_type' => 'Mediagallery' );
if ( have_posts() ) : while ( have_posts() ) : the_post();

<h1><?php the_title(); ?></h1>
<?php echo  apply_filters( 'the_content'  ,  types_render_field('mediaid')); ?>

<?php endwhile; ?> 
<?php else : ?> <?php endif; ?> <?php wp_reset_query(); ?>

When i change post_per_page to 2 they correctly show up both, so the post it there but it only shows one (the newest post), i tried different things But somehow i can only show the newest and all posts are loading that content ?

i hope someone can help me,


share|improve this question

I ... want to ... switch the posts with a next & prev button in [a] sidebar.

But only the permalink ... changes.

You do not say what the permalink is changing to. It sounds like you might be talking about pagination in a custom loop. Your query ignores the page number and always returns page 1.

I don't know how to safely use query_posts(). Here is a solution using the WP_Query object. First it gets the current page number and then it adds that number to the query. (I removed the else and the if clause since they were not doing anything and stopped all that jumping in and out of PHP.)

$page_number = ( get_query_var('paged') ) ? get_query_var('paged') : 1;

$media_gallery = new WP_Query( array(
    'paged'          => $page_number,
    'posts_per_page' => 1,
    'post_type'      => 'Mediagallery',
) );

while ( $media_gallery->have_posts() ) {

    printf( '<h1>%s</h1>', get_the_title() );
    echo apply_filters( 'the_content', types_render_field('mediaid') );

share|improve this answer
Thanks for the response man, however the result is the same.. For example, i have a post with the permalink . racing:8888/mediagallery/supercup-600 & one with racing:8888/mediagallery/supercup-1000. & racing:8888/mediagallery/test They all link to the most recent post(supercup 600). When i use the next/prev link or i straight use the permalink they all go to supercup 600. But with the permalink changed to for example supercup 1000. Strangely it doens't seem to find the next post or load the correct content of that post.. – Laurens May 20 '13 at 2:49
You didn't give the urls up top and you still haven't explained the logic behind which posts should appear on each page, so I had to assume what you were doing. Add this information to the original question (using the Edit link) with an explanation of which posts you expect to have on the supercup-1000 page and which posts you expect on the test page, etc. – Charles Clarkson May 20 '13 at 3:08

Your Answer


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.