Support » Fixing WordPress » get_posts returns an empty array

  • Resolved moikirsch

    (@moikirsch)


    I have the following code (sorry for the spanish):

    // Argumentos para traernos el thumbnail
    $argumentos = array(
    	'posts_per_page' => -1,
    	'orderby' => 'menu_order',
    	'order' => 'ASC',
    	'post_type' => 'attachment',
    	'post_parent' => $post->ID,
    	'post_status' => null,
    	'exclude' => $logo,
    	'post_mime_type' => 'image'
    	);
    
    $imagenes = get_posts( $argumentos );
    
    print_r($argumentos);
    print_r($imagenes);

    The array of arguments seems fine and this is actually a copy/paste from an old code that I was using before but for some reason get_posts is returning an empty array.

    I’m starting to think that the problem might be related to the new media managemente on version 3.5.

    Does anyone know how to accomplish something similar or does anyone can catch the problem?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Michael

    (@alchymyth)

    where is that code located?

    in the main loop?
    is it in a function?

    moikirsch

    (@moikirsch)

    Inside the main loop.

    A sample of the values in $argumentos:

    Array
    (
        [posts_per_page] => -1
        [orderby] => menu_order
        [order] => ASC
        [post_type] => attachment
        [post_parent] => 20
        [post_status] =>
        [exclude] => 39
        [post_mime_type] => image
    )
    moikirsch

    (@moikirsch)

    Fixed! The problema was NOT with this piece of code… there was another filter adding some variables to WP_Query and because of that there was no results.

    After modifying (removing) those filters everything seems to be fixed.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘get_posts returns an empty array’ is closed to new replies.