Order By table field comment_status in WordPress > 4.0

Here’s a way to add an extra Comment Status field to the posts list table: add_filter(‘manage_post_posts_columns’, function ( $columns ) { $_columns = []; foreach( (array) $columns as $key => $label ) { $_columns[$key] = $label; if( ‘title’ === $key ) $_columns[‘wpse_comment_status’] = esc_html__( ‘Comment Status’, ‘mydomain’ ); } return $_columns; } ); add_action( ‘manage_post_posts_custom_column’, … Read more

SQL: What is wrong with the following query (generated by WordPress WP_Query, ordering prices)

Solved. After the edit it was easy. It is allowed to use type => ‘decimal(x,x)’ in meta_query. Maximum precision is decimal(65,30). https://dev.mysql.com/doc/refman/5.7/en/precision-math-decimal-characteristics.html array(6) { [“orderby”]=> array(2) { [“uss_product_price”]=> string(4) “DESC” [“title”]=> string(3) “ASC” } [“meta_query”]=> array(3) { [“relation”]=> string(3) “AND” [“sortprimary_clause”]=> array(3) { [“key”]=> string(17) “price” [“compare”]=> string(6) “EXISTS” [“type”]=> string(13) “decimal(30,5)” } [0]=> array(4) … Read more

add_filter() depending on search term

The pre_get_posts action runs before the posts_join and posts_where filters. So, pre_get_posts is a suitable hook for conditionally adding callbacks to the posts_join and posts_where filters: function wpse249060_pre_get_posts( $query ) { // Make sure we’re doing a search query and that the search // term is NOT ‘something’ if ( $query->is_search() && $query->query_vars[‘s’] !== ‘something’ … Read more

Linking to the most recent post in a Custom Post Type

As long as Pods creates standard custom post types, you can simply update the arguments passed to WP_Query . The$post_type parameter will allow you to filter the results based on the specified post type (string) or post types (array). $latest = new WP_Query( array( ‘category_name’ => $request->query_vars[‘category_name’], ‘posts_per_page’ => 1, ‘post_type’ => array ( ‘post’, … Read more

Return only post(s) which have post_excerpt

Something along these lines should work, not tested for syntax errors though function random_post() { $args = array( ‘post_type’ => ‘post’, ‘orderby’ => ‘rand’, ‘posts_per_page’ => 1, ); $post = query_posts( $args ); } if(!$post->post_excerpt){ random_post(); } // Then down here you would do whatever with the $post object

Query/list all terms and their custom post count

If the taxonomies in question are used ONLY in the post_type in question, then the following simple function will do what you need: function count_term_use ($post_type) { $args = array ( ‘taxonomy’ => get_object_taxonomies ($post_type, ‘names’), ) ; foreach (get_terms ($args) as $term) { echo “$term->name – $term->count\n” ; } return ; } However, if … Read more