wordpress get_children won’t work after pre_get_posts

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 cstm_get_posts() {
        if ( is_post_type_archive( 'tent' ) ) {
        $query->set( 'posts_per_page', 20 );
 add_action('pre_get_posts', 'cstm_get_posts' );


 $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?

Leave a Reply


Hire Me
Follow Me!
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.