Hi,
Sorry im not sure what the issue is.
If you don’t specify a category then it will grab all posts.
i mean, if i put this ALM shortcode:
[ajax_load_more post_type="post" category="football,tennis,boxe" offset="3"]
offset works only for football category.
i tried also doing this:
$post_ids = array();
while (have_posts()) : the_post();
$post_ids[] = get_the_ID();
endwhile;
?>
and
if($post_ids){
//Implode the posts and set a variable to pass to our exclude param.
$postsNotIn = implode(",", $post_ids);
}
echo do_shortcode('[ajax_load_more post_type="post" exclude="'.$postsNotIn.'" button_label="load more posts"]');
it works but don’t know why main loop misses 4 posts even if i see them on homepage.
Please help me
All offset does is skips the first ‘x’ number of posts. Are you ordering the posts correctly?
offset works only with one category and not with an array of them.
i well know how offset works. the problem is:
if i have 3 categories. i want offset for three of them not just one.
how to sort it out?
about option two (excluding posts).
How is it possible that loop ignores 4 posts I see on the homepage?
You can’t offset each individual category. If you are querying 3 categories and offsetting 4 posts then you are only offsetting 4 posts not 12.
You would need to run 3 separate category queries and store the post IDs in you $post_id variable.
Then run ALM and pass $post_id like you are above.
do u mean something like this?
<?php
// WP_Query arguments
$args = array (
'cat' => '2',
'pagination' => true,
'posts_per_page' => '6',
'order' => 'DESC',
'offset' => 4,
);
$my_query = new WP_Query( $args );
?>
<ul>
<?php
if ( $my_query->have_posts() ) {
while ( $my_query->have_posts() ) {
$my_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php
}
} ?>
</ul>
<?php
wp_reset_postdata();
?>
-----
-----
<?php
$args = array (
'cat' => '3',
'pagination' => true,
'posts_per_page' => '6',
'order' => 'DESC',
'offset' => 4,
);
$my_query = new WP_Query( $args );
?>
<ul>
<?php
if ( $my_query->have_posts() ) {
while ( $my_query->have_posts() ) {
$my_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php
}
} ?>
</ul>
<?php
wp_reset_postdata();
?>
how to put the 3 merged queries into ALM shortcode?
thank you
Something like this…
Sorry I dont have time to actually code this for you.
$post_ids = array();
Query #1
while….
$postIds[] = $post_ids[] = get_the_ID();
endwhile…
Query #2
while….
$postIds[] = $post_ids[] = get_the_ID();
endwhile…
Query #3
while….
$postIds[] = $post_ids[] = get_the_ID();
endwhile…
if($post_ids){
//Implode the posts and set a variable to pass to our exclude param.
$postsNotIn = implode(",", $post_ids);
}
echo do_shortcode('[ajax_load_more post_type="post" category="category1, category2, category3" exclude="'.$postsNotIn.'" button_label="load more posts"]');
thanks for suggestion.
i did different queries and I merged them into one array.
it works perfectly now
π