A little help here with get_children
function. pre_get_posts
hook filter the main_query. After that I called get_children
to get the attachment image but I ended up giving an 0 array result.
function.php
function cstm_get_posts() {
if ( is_post_type_archive( 'tent' ) ) {
$query->set( 'posts_per_page', 20 );
return;
}
}
add_action('pre_get_posts', 'cstm_get_posts' );
archive.php
$attachments = get_children( array(
'numberposts' => 1,
'order'=> 'ASC',
'post_mime_type' => 'image',
'post_parent' => $post->ID,
'post_type' => 'attachment'
));
foreach($attachments as $attch){
code display image here
}
Code above is just a snippet.
Anyway if I don't use pre_get_posts
the get_children
works fine. But I need the pre_get_posts
to filter the query. Any idea or suggestion?