Support » Themes and Templates » Retrieve attachments from subpages

  • 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 🙂

  • The topic ‘Retrieve attachments from subpages’ is closed to new replies.