WordPress.org

Ready to get started?Download WordPress

Forums

Retrieve attachments from subpages (1 post)

  1. aneemal
    Member
    Posted 2 years ago #

    Hi All,

    I'm hoping someone can help me figure out a problem I'm having in calling a function (defined in my functions.php file) from a custom theme template.

    The well-used bdw_get_images() code works well when called from the single.php, but when I try to use this on a custom page, no pictures appear. I tested that the variable $postId is successfully being passed to the function (using an 'echo' statement), but the function doesn't return any pics.

    I'm trying to call the function from within a loop that I was hoping would retrieve the subpages of the current page and the run the bdw_get_images function for each of those pages.

    This is the code I have on my custom template:

    $mypages = get_pages(array('child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'desc'));
    	$cn = 0;
    	foreach ($mypages as $page) {
    	    bdw_get_images($page->ID, null);
    	};

    This is the bdw_get_images function in functions.php:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    I hope someone can spot my mistakes!!

    Thanks :)

Topic Closed

This topic has been closed to new replies.

About this Topic