Complicated MySQL Query

Why not just use WP_Query for this instead of inventing the wheel all over again? I’m pretty sure you can solve this with a meta query within your WP_Query. See the codex.

MySQL: get post_tag items that are tags (not SEO keywords)

Fetching all tags of post: SELECT p.id, p.post_name, c.name, GROUP_CONCAT(t.`name`) as tag FROM wp_posts p JOIN wp_term_relationships cr on (p.`id`=cr.`object_id`) JOIN wp_term_taxonomy ct on (ct.`term_taxonomy_id`=cr.`term_taxonomy_id` and ct.`taxonomy`=’category’) JOIN wp_terms c on (ct.`term_id`=c.`term_id`) JOIN wp_term_relationships tr on (p.`id`=tr.`object_id`) JOIN wp_term_taxonomy tt on (tt.`term_taxonomy_id`=tr.`term_taxonomy_id` and tt.`taxonomy`=’post_tag’) JOIN wp_terms t on (tt.`term_id`=t.`term_id`) GROUP BY p.id order by p.id … Read more

Delete posts with word count less than x number of words

function delete_posts() { $lastposts = get_posts(array(‘numberposts’ => -1)); if ( $lastposts ) { foreach ( $lastposts as $post ) : setup_postdata( $post ); ?> <?php $content = get_the_content(); if (str_word_count($content) < 100) { wp_trash_post($post->ID); } ?> <?php endforeach; wp_reset_postdata(); }}add_action( ‘init’, ‘delete_posts’ );

How WP decide to show or not to show in admin panel the pop-up window with hint? Need a fix

Dismissed pointers are stored as user meta, you can inspect this for yourself with: $meta = get_user_meta( wp_get_current_user() ); print_r( $meta[‘dismissed_wp_pointers’] ); In your case, the meta might be empty or damaged, to update dismissed pointers for ALL users on your blog, you could run this function (only once): function wpse80084_dismiss_wp_pointers() { $dismissed = array( … Read more

Woocommerce: Grab total revenue of a product over all orders

Got it solved. Probably not the most efficient way but it works! SELECT product_id, meta_value FROM ( SELECT order_meta.order_item_id, order_meta.meta_value AS ‘product_id’ FROM wp_woocommerce_order_itemmeta AS order_meta LEFT JOIN wp_woocommerce_order_items AS order_items ON order_meta.order_item_id = order_items.order_item_id LEFT JOIN wp_term_relationships AS term_rels ON term_rels.object_id = order_items.order_id WHERE term_taxonomy_id = 24 AND order_meta.meta_key = ‘_product_id’ ) AS product_ID … Read more

Query sql for truncate post_content in wp_posts table

Backup your db Remeber to backup your db Import the backup in another database, change wp-config.php to use this new database and see if everithing is ok. (Importing is successfull? Site appear without any change?) WordPress uses a prefix for table names. The default is ‘wp_’ but clever guys change it with something else. (The … Read more