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.

It is possible for shortcodes? Paggination works fine on custom template page.But I want to display the posts with shortcodes. Posts are displayed well.But pagination works incorrectly.The same posts on all pages. My custom query loop in page template:

$page = (get_query_var('paged')) ? get_query_var('paged') : 1;  
        $args = array(
    'posts_per_page' =>'1', 
    'orderby' => 'post_date',
    'paged' => $paged,
    'post_type' => 'accomodation',
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'accomodation_category',
            'field' => 'slug',
            'terms' => 'gostinnitsy-2'
        ),
        array(
            'taxonomy' => 'location',
            'field' => 'slug',
            'terms' => 'litva'
        )
    )
);
$custom_query = new WP_Query( $args );
// Pagination fix
$temp_query = $wp_query;
$wp_query   = NULL;
$wp_query   = $custom_query;

?>

  
 have_posts() ) :
    while ($custom_query-> have_posts() ) :
        $custom_query->the_post();?>
                






  

max_num_pages );


$wp_query = NULL;
$wp_query = $temp_query;?>

And my shortcode in function.php


function accomodation_catalog_shortcode( $atts )
{
extract(shortcode_atts(array(
     'accomodation' => '',
     'location'     => '',
     'number'       =>'-1',
     'orderby'      => 'post_date'
   ), $atts));
    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;  
     global $post;
        $args = array(
    'posts_per_page' =>$number, 
    'orderby' => $orderby,
    'paged' => $paged,
    'post_type' => 'accomodation',
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'accomodation_category',
            'field' => 'slug',
            'terms' => $accomodation
        ),
        array(
            'taxonomy' => 'location',
            'field' => 'slug',
            'terms' => $location
        )
    )
);
$custom_query = new WP_Query( $args );
// Pagination fix
$temp_query = $wp_query;
$wp_query   = NULL;
$wp_query   = $custom_query;

?>

  
 have_posts() ) :
    while ($custom_query-> have_posts() ) :
        $custom_query->the_post();?>
                






  

max_num_pages );


$wp_query = NULL;
$wp_query = $temp_query;?>

    

I corrected the error:'paged' => $page, and pagination work!

But why when I want to display shortcode content under page content, shortcode content are displayed above page content?

In admin:

<p>page content<p>
[ accomodation-catalog location='slug ' accomodation='slug']

display

<div>shortcode content</div> <p>page content<p>

What is wrong?

share|improve this question
    
possible duplicate of How to fix pagination for custom loops? –  Chip Bennett Oct 31 '13 at 13:41
add comment

1 Answer 1

Hmmm... It looks like your shortcode function defines $page, but the query itself uses $paged....with a d on the end. Maybe remove the d? In other words, try changing

'paged' => $paged

into

'paged' => $page
share|improve this answer
    
Thanks! It's work! –  elenakoroleva Oct 31 '13 at 4:41
add comment

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.