WordPress Betheme: Unkown subheader image of a child page

admin2025-06-06  8

I want to get the URL of the Muffin Betheme subheader image of a child page, in the parent one, for each of its children.

Thus, I go through the children, then I try to get the subheader image for each child and I display it.

foreach (get_page_children(get_the_ID(), (new WP_Query())->query(array('post_type' => 'page', 'post_status' => 'publish'))) as $child) {

    $html_to_display .= '<a href="' . get_permalink($child) . '"><img src="' . wp_get_attachment_image_src($child->ID, 'large') . '" />' . get_the_title($child) . '</a>';

}

However, wp_get_attachment_image_src($child->ID, 'large') returns:

Unknown

I checked out the subheader image of this child, and the upload actually exists.

Question

How could I display this subheader image correctly?

Metaquestion

What tags would you recommend me to use in this SO question?

I want to get the URL of the Muffin Betheme subheader image of a child page, in the parent one, for each of its children.

Thus, I go through the children, then I try to get the subheader image for each child and I display it.

foreach (get_page_children(get_the_ID(), (new WP_Query())->query(array('post_type' => 'page', 'post_status' => 'publish'))) as $child) {

    $html_to_display .= '<a href="' . get_permalink($child) . '"><img src="' . wp_get_attachment_image_src($child->ID, 'large') . '" />' . get_the_title($child) . '</a>';

}

However, wp_get_attachment_image_src($child->ID, 'large') returns:

Unknown

I checked out the subheader image of this child, and the upload actually exists.

Question

How could I display this subheader image correctly?

Metaquestion

What tags would you recommend me to use in this SO question?

Share Improve this question asked Nov 12, 2018 at 11:31 JarsOfJam-SchedulerJarsOfJam-Scheduler 1012 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Use get_the_post_thumbnail_url() instead of wp_get_attachment_image_src()

wp_get_attachment_image_src(): this function takes attachment id as first parameter

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749190273a317119.html

最新回复(0)