Of course, I followed a path, but I did not reach the result, first I get all post IDs of a category with this code :
<?php
$cat_posts = get_posts(array(
'category' => 42,
'numberposts' => -1
));
$parent_ids = array_map('get_post_ids', $cat_posts);
function get_post_ids($post_obj) {
return isset($post_obj->ID) ? $post_obj->ID : false;
}
?>
and then I add $parent_ids to shortcode, but its not work!
<?php echo do_shortcode('[ajax_load_more posts_per_page="12" post_type="attachment" custom_args="post_parent:'.$parent_ids.'" post_status="inherit"]'); ?>
thanks but it doesn’t help.
below shortcode show attachments of a specific post, is there a way to add multiple ids to this code?
for example “post_parent:50,51,52” instead of “post_parent:50”, if Found a solution for this probably my problem will solved.
[ajax_load_more post_type="attachment" custom_args="post_parent:50" post_status="inherit" preloaded="true"]
Ok, I’m not sure then. Might not be possible using only the shortcode.
If you can write a working WP Query of what you’re looking for I can instruct you how to do it with Ajax Load More.
this is a working WP Query, this code first get all post IDs of a category, then show attachments of that posts.
<?php
// get all posts of a certain category
$query = new WP_Query(
array(
'cat' => 42,
'posts_per_page' => -1,
'fields' => 'ids'
));
// get all attachments of posts form previous query and show them
$image_query = new WP_Query(
array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'post_parent__in' => $query->posts,
'posts_per_page' => 10,
));
if( $image_query->have_posts() ){
while( $image_query->have_posts() ) {
$image_query->the_post();?>
<?php $imgurl = wp_get_attachment_image($image->ID, 'thumbnail');
echo '<a style="display:inline-block;" href="';
echo get_permalink();
echo '">';
echo $imgurl;
echo '</a>';?>
<?php } } ?>
ok thanks.
have you tried ‘post_parent_in’ in the custom args?
I might have to try this tomorrow.
I used ‘post_parent_in’ and its not working. And of course I tried a few other solutions, none of them worked!
I think it may not be possible to do this with alm
I solved it by using : https://connekthq.com/plugins/ajax-load-more/docs/filter-hooks/#alm_query_args
Thanks for good support
-
This reply was modified 2 years, 2 months ago by
ehsanmn.