0

I have a strange issue that i don't really understand, I explain : In my tag.php, i have an infinite scroll with custom post types thanks to the active tag and ajax.

$posts = get_posts( array(
    'post_type' => 'video',
    'posts_per_page' => 6,
    'paged' => 1,
    'post_status' => 'publish',
    'post__not_in' => $posts_not_in,
    'tax_query' => array(
            array(
                'taxonomy' => 'post_tag',
                'field'    => 'id',
                'terms'    => $theme->term_id,
                'operator' => 'IN'
            )
     )
)) ;

I do the same get_posts in functions.php in my ajax function

add_action( 'wp_ajax_get_posts_theme', 'get_posts_theme' );
add_action( 'wp_ajax_nopriv_get_posts_theme', 'get_posts_theme' );

function get_posts_theme() { ... }

and it displays differents posts results. Why ? Any ideas ? Thanks for help me.

0

Some arguments for your query are with variables, we don't know how you define them in the function. i.e : $posts_not_in can be the same or not. And will change your results. Same for $terms.

You maybe need to introduce an offset var and add it to each query.

0

Ok i restart, even this simple get_posts not returning same values !

$posts = get_posts( array(
    'post_type' => 'video',
    'posts_per_page' => 6,
    'paged' => 1,
    'post_status' => 'publish'
)) ;

I replaced 'paged' with 'offset' and nothing changed !

How it's possible ? What i forgot ?

If i add 'order' => 'ASC' and 'orderby' => 'ID' for example, it's the worst !

I have a problem with my custom post type video because if i replace by 'posts' it works well !

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.