Tag Info

New answers tagged

0

The images where setted by woocommerce, In case someone needs, this is how I did it $thumb_id = get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true ); $term_img = wp_get_attachment_url( $thumb_id );


1

Taxonomies don't by default have thumbnail images. Without knowing how those are set I can't say exactly how to get the thumbnails, but as for "what am I doing wrong?" get_post_thumbnail_id accepts a post ID or lacking that assumes the current post in the Loop. You are passing it a term_id, which isn't going to work. You can see that in the source: 32 ...


0

All attachments has got a post parent which you can access with $post->post_parent inside the loop or get_queried_object()->post_parent outside the loop on your image.php or similar single post pages. (See my question here and the answer by @gmazzap why you should rather avoid $post outside the loop) Now that you have the post parent ID, it is easy to ...


0

As of WordPress 4.2 this functionality is built in. Click the Detach link in media list view. For older versions, there's a plugin which does the same thing: https://wordpress.org/plugins/unattach/ Unattach is a very simple plugin which allows detaching images and other media from WordPress posts, pages and other content types.


1

You don't get any ordering, because you are making multiple get_posts() calls and only retrieve a single post in each of them. You cannot order a single post. :) You need to get rid of outermost loop and just pass a set of IDs (that would be your $instance['data']) to retrieve via single get_posts() call.


0

Like I said, in your custom scenario, after getting the results, here is your how you can do it: $data_attach = get_posts($args); $title_array = array(); foreach ($data_attach as $data) : $title_array[] = $data->post_title; endforeach; sort($title_array); foreach ...


2

Because the credit data is saved in the attachment's post meta, not the main post: $credit = get_post_meta( $post->ID /* Wrong ID! */, 'credit', true ); Instead you need to catch the ID of the inserted image: function attach_image_credit( $images ) { $return = $images[0]; // Get the image ID from the unique class added by insert to editor: ...


0

Figured it out! The culprit was the plugin "Add Categories to Pages" which one of my editors had added to the site. In addition to registering post_tag and category for the page post type, it also modified the archive.php and tag.php queries to only look in the post and page types---yet another solution for the issue of including posts, pages, and ...


0

If you change the structure of the permalink, you have to provide the rewrite rules to understand the new structure. Also, you are not building the attachment permalink correctly. The next code is working: add_filter( 'attachment_link', 'wpd_attachment_link', 20, 2 ); function wpd_attachment_link( $link, $attachment_id ){ $attachment = get_post( ...


1

The WP_Query documentation on the codex specifically says: 'attachment' - an attachment. Whilst the default WP_Query post_status is 'publish', attachments have a default post_status of 'inherit'. This means no attachments will be returned unless you also explicitly set post_status to 'inherit' or 'any'. I am not sure why it was working before ...


0

So there are several ways images can be "related" to post: When you upload image in post context that post is set as its parent (that is parent field of image attachments post has post's ID). When you set image as a featured on a post (or use similar functionality from custom fields frameworks) the post records image attachment's ID in it its meta. When ...


0

Consider looking at wp_prepare_attachment_for_js( $attachment ), where $attachment is the WP_Post object of the attachment itself. This is a bit of a "kitchen sink" function, but it does provide a very nice hash with a ton of metadata, including 'alt': $response = array( 'id' => $attachment->ID, 'title' => ...



Top 50 recent answers are included