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

Adding Featured Image to Post programatically

For each image/post combination, run the following. $image_name is the filename, $post_id is the post ID. if( $image_name != ” && !has_post_thumbnail( $post_id ) ){ $base = get_stylesheet_directory(); $imgfile= $base . ‘/import/’ . $image_name; // Images are stored inside an imports folder, in the theme directory $filename = basename($imgfile); $upload_file = wp_upload_bits($filename, null, file_get_contents($imgfile)); if … Read more

How I upload, save and set a featured image from my frontend?

sorry this isn’t an answer but you need to sanitize that user input. Your allowing tags to be written directly into your post content which allows anyone to run javascript in both wp admin and on the front end of your site (assuming you’ll eventually print these posts). highly recommend (at minimum) strip_tags() or htmlspecialchars() … Read more

How to add a background image to category and display image on category page

You can try this code. It will add a media button which will get the image url. I have commented the parts that I have deleted or added. function my_category_module() { // this action is deprecated //add_action(‘edit_category_form_fields’, ‘add_image_cat’); // Add these actions for edit and add add_action(‘edited_category’, ‘save_image’); add_action(‘create_category’, ‘save_image’); add_action(‘category_edit_form_fields’, ‘edit_image_cat’); } add_action(‘init’, ‘my_category_module’); … 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