How to check featured image exist or not in post

$args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => -1);

$the_query = new WP_Query( $args );
$i = 1;

if ( $the_query->have_posts() ) {

echo ‘<ul>’;

while ( $the_query->have_posts() ) {

$the_query->the_post();

if ( has_post_thumbnail() ) {

$dom_url = get_the_post_thumbnail_url();

$new_url = str_replace(‘site_url()’,’/var/www/html/’,get_the_post_thumbnail_url()); if(!file_exists($new_url))

{

echo ‘<li><b> ‘ .$i. ‘ </b> ‘. get_the_title() . ‘ Page Link:——-‘. get_the_post_thumbnail_url() .'</li>’;

$i++;

}

}

}

echo ‘</ul>’;

wp_reset_postdata();

} else {

// no posts found

}
echo “Number Of Posts: “.$i;

Check root path of image $_SERVER[‘DOCUMENT_ROOT’]

Remove WooCommerce styles and scripts

Remove WooCommerce default css and js of lightbox then implement any plugins like:-

  1. Twist – Woocommerce Product Gallery Slider
  2. Responsive Lightbox

 

/* Remove WooCommerce styles and scripts. */
function woo_remove_lightboxes() {

// Styles
wp_dequeue_style( ‘woocommerce_prettyPhoto_css’ );

// Scripts
wp_dequeue_script( ‘prettyPhoto’ );
wp_dequeue_script( ‘prettyPhoto-init’ );
wp_dequeue_script( ‘fancybox’ );
wp_dequeue_script( ‘enable-lightbox’ );
}

add_action( ‘wp_enqueue_scripts’, ‘woo_remove_lightboxes’, 99 );

Remove All products or attributes with SQL commands WooCommerce

Remove all attributes from WooCommerce

DELETE FROM wp_terms WHERE term_id IN 
(SELECT term_id FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%');
DELETE FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%';
DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN 
(SELECT term_taxonomy_id FROM wp_term_taxonomy);

Delete all WooCommerce products

DELETE FROM wp_term_relationships WHERE object_id IN 
(SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'));
DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type IN 
('product','product_variation'));
DELETE FROM wp_posts WHERE post_type IN ('product','product_variation');

Delete orphaned postmeta

DELETE pm
FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
WHERE wp.ID IS NULL

Add New Admin User in WordPress by MySql Query

INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`)
VALUES (‘newadmin’, MD5(‘pass123’), ‘firstname lastname’, ‘email@example.com‘, ‘0’);

INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, (Select max(id) FROM wp_users), ‘wp_capabilities’, ‘a:1:{s:13:”administrator”;s:1:”1″;}’);

INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, (Select max(id) FROM wp_users), ‘wp_user_level’, ’10’);