admin管理员组

文章数量:1133739

I've added some custom fields to a rest route. I want to retrive the post thumbnail for my CPT and I'm using this code:

This is the code I'm using to add the post meta to the CPT after an image is selected and the post is published. If not clear I'm not using the default WP UI but a customnized one based on vue.js

                    $post_published = wp_update_post( 
                        array(
                            'ID' => $post_id,
                            'meta_input' => array(
                                'post_thumbnail' => get_the_post_thumbnail_url( $post_id )
                            ),
                            'post_status' => 'publish'
                        ), 
                        true, 
                        true 
                    );

The url will look like this localhost/wp-content/uploads/23/09/myimage.png and into the wp-admin custom dashboard the system will try to load this kind of url http://localhost/mysite/wp-admin/localhost/mysite/resources/uploads/2023/09/customimage-min-2.png

Anyway I've noticed that in my customized wordpress dashboard the link will be loaded in a wrong way, by inspecting the DOM I've noticed that the url of the thumbnail will be appended to the wp-admin one and this will result in a failed load. Is there a way to fix this?

本文标签: post thumbnailsUnable to get the correct URL using getthepostthumbnailurl() in wpadmin