Preserve term order per post in a non-hierarchical taxonomy

I encountered a similar issue and this is how I solved it. Note that I put in Fruits as the taxonomy name based on your example. It’s important that this name matches the taxonomy name exactly. Often taxonomy names are singular, i.e. fruit function wp4382_filter_terms_order( $orderby, $query_vars, $taxonomies ) { if ( ! empty( $query_vars[‘object_ids’] … Read more

How to Orderby Comments by post title?

The WP_Comment_Query class supports ordering by: ‘comment_agent’, ‘comment_approved’, ‘comment_author’, ‘comment_author_email’, ‘comment_author_IP’, ‘comment_author_url’, ‘comment_content’, ‘comment_date’, ‘comment_date_gmt’, ‘comment_ID’, ‘comment_karma’, ‘comment_parent’, ‘comment_post_ID’, ‘comment_type’, ‘user_id’, ‘comment__in’, ‘meta_value’, ‘meta_value_num’, There’s a way to adjust it via filters so we can support ordering by the post title: $args = [ ‘status’ => ‘approve’, ‘post_status’ => ‘publish’, ‘post_type’ => ‘post’, ‘orderby’ => … Read more

SQL query to retrieve all the records that have not indicated category

If I understand the question, you’re looking for the SQL for the equivalent of $args = array ( ‘post_type’ => ‘popular_music’, ‘post_status’ => ‘publish’, ‘tax_query’ => array ( array ( ‘taxonomy’ => ‘category’, ‘operator’ => ‘NOT EXISTS’, ), ), ‘posts_per_page’ => -1, ‘orderby’ => ‘ID’, ‘order’ => ‘DESC’, ) ; $query = new WP_Query ($args) … Read more

With W3 Total Cache when I publish a post it does not appear in the homepage. Only if i purge all cache [closed]

You are most likely using browser caching ? Therefore new visitors would see the newly published post just fine, but because you’ve previously visited the page its cached and therefore your browser cache hasnt expired. Generally its good practice to clear all caches upon publishing posts/pages and/or activating or deactivating a plugin. You can also … Read more

Comma separated all attached image ID numbers except featured image ID number

If we want to exclude the featured post image then here’s the one-liner updated: $ids = join( ‘,’, wp_filter_object_list( get_attached_media(‘image’ ), [ ‘ID’ => get_post_thumbnail_id() ], ‘NOT’, ‘ID’ ) ); here it’s expanded: $ids = join( ‘,’, // join array by comma wp_filter_object_list( get_attached_media(‘image’ ), // fetch attached images [ ‘ID’ => get_post_thumbnail_id() ], // … Read more

Applying $posts_clauses filter to specific queries only

I had the same problem of needing to only apply $post_clauses to specific loops/queries and was able to use THIS solution provided by Stephen Harris: You can access query variables (including custom ones) via the WP_Query::get() method. For example: $my_query = new WP_Query( array( … ‘wpse105219_custom_var’ => ‘foobar’, … ) ); To ‘catch’ this at … Read more