To get the URL of the uploaded image/attachment, you can use wp_get_attachment_url()
(which always returns the full-sized image URL) or wp_get_attachment_image_url()
for image attachment:
// This is how you should call uploadImageToMediaLibrary(); assign the value to $att_id.
$att_id = uploadImageToMediaLibrary($post->ID, $external_url, "custom_alt");
$url = wp_get_attachment_image_url( $att_id, 'full' ); // full-sized URL
But to set the image as the featured image of the post where the image was uploaded to, or any posts actually, then you would use set_post_thumbnail()
like so:
$att_id = uploadImageToMediaLibrary($post->ID, $external_url, "custom_alt");
if ( ! is_wp_error( $att_id ) && $att_id ) {
set_post_thumbnail( $post->ID, $att_id );
}
PS: I revised this answer because using set_post_thumbnail()
is much preferred than manually updating the private metadata _thumbnail_id
used for post featured images.. =)
Related Posts:
- Creating a metabox to upload multiple images, Ignoring The Featured Image
- How to hide CPT files from media library programmatically
- Add metabox with media uploader in a custom post type [duplicate]
- How to Removing fields from the Media Uploader/Gallery on a Custom Post Type Edit Page
- get_terms won’t display product_cat or any other custom taxonomies when specified
- Remove fields on media uploader for custom page type – not working for “From Computer” or “From Url” tabs?
- Duplicate Custom Header Functionality into the post edit screen
- Redirect to another page using contact form 7? [closed]
- File sharing platform for user contributions? [closed]
- Cannot upload featured image to a custom post type
- How to manage a bookstore
- Issue On Listing Woocommerce Parent Tag List
- Media library – Limit images to custom post type
- How can I bulk upload images and automatically create posts for each one at the same time?
- Use a separate upload folder for custom post attachment upload
- Custom Taxonomies Terms as Post Title for Custom Post Types upon Publishing
- How to get term link that crosses different custom post types?
- Attach a Custom Post Type to a Woocommerc product as a variation or add-on [closed]
- Not Able to Insert Taxonomy Term Using wp_insert_post()
- array_pop() expects array, boolean given for $event_type_term ->slug
- post count is wrong when using same taxonomy for 2 different CPT
- Glossary with Custom Post Type
- Displaying custom post type by first letter through custom taxonomy
- How to solve suspected memory issue in custom WordPress loop?
- Separate Custom Post Type Taxonomy by Comma
- Image size filtering in Media uploader according to custom post type
- Custom Search | Wrong output & question
- Rename the insert button in media upload window
- Trouble adding custom featured image for custom taxonomy TERMS
- Get child terms of current term of the current post
- Change upload_dir folder at a certain cpt but cant change back
- List all custom post type posts from a given category?
- Get the terms of a custom taxonomy for a specific author in author template
- Set meta_query only for specific post type
- Upload Image from Front End and Resize
- Category page only displaying the posts from a custom type
- Woocommerce query specific product from specific category
- How to rename image at uploading on specific plugin or post-type in WordPress
- How to get posts from multiple custom post types according to it’s custom taxonomy terms?
- How to check the terms in single custom post type template
- Create custom post type on successful woocommerce order [closed]
- window.send_to_editor and jQuery .attr() conflicts with multiple custom upload image meta boxes
- Displaying a custom post types custom taxonomy value?
- Show listings from Impress Listing plugin in random order using taxonomy and terms
- How to display product subcategories into my custom post type single page
- How do I display tags for a custom post type single page?
- Get image post ID in media upload
- using $wpdb to get custom post type with term
- Allow user to set custom order to a list of custom taxonomies?
- Which post does a taxonomy term belongs to?
- Issue on Creating Custom Tax Term Dynamically From Another CPT Meta-box On Publish
- WooCommerce Customer Role Delete Custom Post Type
- WordPress loop: Show only a Custom Post Type Taxononmy TERM
- How do I require the specification of term in a custom post type and custom taxonomy?
- How to Get WordPress custom post data in WooCommerce product meta panel? [closed]
- Displaying custom-taxonomy-terms sorted by parent/child-hierarchy?
- Category archive in with conjunction with custom post type is empty
- Add arguments to get_the_terms for custom post types
- How to set up Custom Post Type archive page as Front page
- How to Display Posts From Category Within a Custom Taxonomy?
- how to count the current posts terms
- How can I get 3 different taxonomy type terms in a div class element?
- Get terms for a specfic post from multiple taxonomies in custom post type
- Custom Post Type Taxonomy Term Order by Title
- Add custom post type taxonomy tag to article class
- Custom Taxonomy dont save in a frontend form for post a custom post
- Custom taxonomy not saving correctly
- Get_the_term_list inexplicably adds values in foreach
- Get List of Terms based on a given term (different taxonomy)
- display post count in archive page that have relation with another taxonomy term
- Return multiples taxonomies with wp_get_object_terms
- Why this didn’t work if i use get_the_ID(), but works if i pass the numeric id
- Duplicate the “Orders” list on Admin Page
- get taxonomies from terms
- Excluded Custom Taxonomy Term Posts Displaying in loop
- Sudden 404 pages on product category archives
- Change display of product price on product show page only
- Get all posts for custom taxonomy term
- posts_per_page is not working by term
- WooCommerce – Custom related product (Spareparts)
- Convert attribute woocommerce terms (taxonomy terms) in posts of custom post type
- WooCommerce change
- Add active class to foundation 6 tabs while looping categories
- Search in multiple specific post types
- Saving Child Terms on front end not setting parent
- Multi Photo Upload with Caption on Front End for Custom Post Type
- how it’s possible to show from a post of a custom post type the taxonomy/terms?
- Filter By Term Not Working – Custom Post Type
- Get posts of an specific term of a custom taxonomy
- Custom Taxonomy is disabled on Edit page
- Get Non-Paginated Index of Post in Paginated Query
- Fetch posts list from fist CPT taxonomy term and list under 2. CPT
- How to List CPTs Under One Tax Term
- Get a list of categories ids
- Using get_terms() as shortcode attribute
- taxonomy terms array not working
- Taxonomy Query of Custom Post Displays Archive Instead of Posts
- List custom taxonomy terms
- Changing upload directory and migrating old attachments
- Taxonomy Archive URL + Template