Support » Fixing WordPress » get_children not working in category page

  • I’m using get_children() in a function that displays all the images attached to a post.

    $images = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );

    It works great when called the function is called from single.php but it doesn’t retrieve any images when called from category.php.

    Can anyone help me?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Any ideas why get_children() would work on some pages and not on others?

    The same code is being called from both my single.php and my category.php.



    Forum Moderator

    can you paste the full code of the category.php (and probably also single.php as a comparison) into a and post the link to it here?

    isolated lines of code can behave totally different depending on the location they are embedded into a template.

    I pasted category.php and single.php. They both call a function named get_main_images() which contains the get_children call. I included the get_main_images function in the bin as well.


    HELP! I can’t figure this out. The code for category.php and single.php are virtually identical. get_children() works in single.php and won’t in category.php. Yet both are set to display the same post.

    Can someone please help me with this?



    Forum Moderator

    try to add global $post; at the beginning of the function:

    function get_main_image($size = 'large', $limit = '1', $offset = '0', $post) {
            global $post;
            $images = get_children( a.......

    Thanks, but that didn’t work.

    This is so weird. My two image functions that call get_children both work when they’re on my blog and my archive and my single posts. It’s only in category that they don’t work. Is there something about category that would prevent get_children from retrieving attached images?

    Here’s how we solved it. We added ‘attachment” to our post_type for our category page. Too, too simple.

    post_type (string / array) – use post types. Retrieves posts by Post Types, default value is ‘post’;

    ■’any’ – retrieves any type except revisions
    ■Custom Post Types (e.g. movies)

    jcowart, can you explain what you did? I’m trying to acheive the same thing. Didn’t you have post-type attachement in your initial call?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘get_children not working in category page’ is closed to new replies.