Set (featured) thumbnail for post?

Perhaps use set_post_thumbnail()? (Codex ref.) EDIT To get the attachment ID using the Post ID: // Associative array of attachments, as $attachment_id => $attachment $attachments = get_children( array(‘post_parent’ => $post->ID, ‘post_status’ => ‘inherit’, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘order’ => ‘ASC’, ‘orderby’ => ‘menu_order ID’) ); $attachment = $attachments[0]; // ID of your single, … Read more

Fallback default image when there is no featured image

Method 1: Set Default Fallback Image for Post Thumbnails Using Plugin This method is easier and recommended for all users. First thing you need to do is install and activate the Default Featured Image plugin. https://wordpress.org/plugins/default-featured-image/ Method 2: Add Fallback Image as Post Thumbnail Manually Your theme’s images folder is located inside /wp-content/themes/yur-theme/ folder. If … Read more

How to change _wp_attachment_metadata specific value in SQL?

You could do this via PHP instead of SQL, just get the existing metadata and change what you need to, it will handling the serializing for you: $newwidth=”250″; // or whatever it is $attachments = get_posts(array(‘post_type’=>’attachment’); foreach ($attachments as $attachment) { $id = $attachment->ID; $metadata = wp_get_attachment_metadata($id); $metadata[‘width’] = $newwidth; wp_update_attachment_metadata($id,$metadata); } But really, you … Read more

How to Remove Two (Related) wp_postmeta Rows?

After 5 hours of searching finally I wrote the SQL query and that is- DELETE FROM {$wpdb->postmeta} WHERE post_id IN (SELECT post_id FROM (SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key LIKE ‘_thumbnail_id’ AND post_id IN(SELECT post_id WHERE meta_key LIKE ‘rafi’)) AS s) I saw your answer above, but using this kinda SQL query for this kinda … Read more

Featured image for news page

If I am reading your question correctly, the problem is that when you set a page so that it has a an archive Loop on it $wp_query and the $posts variable are set to for the index Loop and not for the page the are on. To get information about that page you need get_queried_object. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)