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() ) {
$media_gallery->the_post();
printf( '<h1>%s</h1>', get_the_title() );
echo apply_filters( 'the_content', types_render_field('mediaid') );
}
wp_reset_query();