Support

Account

Home Forums General Issues Get posts(), when used inside of another query, returns nothing.

Helping

Get posts(), when used inside of another query, returns nothing.

  • I need to be able to use restrict manage posts’ get posts() function.

    
    <?php
    add_action('restrict_manage_posts', 'my_manage_posts_fn');
    
    function my_manage_posts_fn()
    {
        $type = 'my_custom_post';
    
        if (isset($_GET['post_type']) && $_GET['post_type'] == $type) {
    
            $args = array('post_type' => 'products', 'posts_per_page' => 100);
            $products = get_posts($args);
            // $products RETURNS EMPTY, WHY?
            // Also, I notice that if I don't set post_type to 'products', it
            // will return the query for my_custom_post
    
        }
    }
    

    Thank you in advance!

  • i dont know what it has to do with acf but check defaults on get_posts() it has publish as default post_status. Do you have published products?

    Also is products the post_type from WooCommerce or is it a self registered? Is it correctly registered an you have product posts published?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.