0

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?

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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