Only show categories that have posts within custom post type

Try Below code: $args = array( ‘post_type’ => ‘work’, ‘posts_per_page’ => -1, ‘post_status’ => ‘publish’ ); $the_query = new WP_Query( $args ); $my_categories = array(); if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); $terms = get_the_terms( get_the_ID(), ‘category’ ); if ( $terms && ! is_wp_error( $terms ) ) : foreach ( $terms … Read more

Get all wp_users sort by metakey

You can index each of the arrays and then orderby 1 or both of them using ASC,DESC as per your requirement $meta_query_args = array( ‘relation’ => ‘OR’, // Optional, defaults to “AND” ‘no_login’ =>array( ‘key’ => ‘user_last_login’, ‘compare’ => ‘Not Exists’ ), ‘login’ => array( ‘key’ => ‘user_last_login’, ‘compare’ => ‘Exists’ ) ); $meta_query = … Read more

taxquery taxonomy get terms

so if $trips_list is the sample trips section, and you want the sample trips to only show trips with the same terms – you’d find the current trips term and argue that in your WP_Query. // this trips terms $tripTerms = wp_get_post_terms( get_the_ID(), ‘reisezweck’); // if each trip only has one term (as its a … Read more

WP_Query about meta_key and its array value

Try this $args = array( ‘post_type’ => ‘book’, ‘posts_per_page’ => -1, ); $query = new WP_Query($args); while($query->have_posts() ) : $query->the_post(); $date = get_post_meta( get_the_ID(), ‘date_all’, true ); if($date[‘year’] >= 2018 && $date[‘month’] == 3){ the_title(); } endwhile; wp_reset_query();

Meta_Query refuses to return results

You forgot the meta_query key in your $args. $meta_query = array( ‘relation’ => ‘OR’, array( ‘key’ => ‘tic_assignment’, ‘value’ => $current_user -> ID, ‘compare’ => ‘=’, ), array( ‘key’ => ‘tic_department’, ‘value’ => $_depts, ‘compare’ => ‘LIKE’, ), ); $_args = array ( ‘post_type’ => ‘tickets’, ‘meta_query’ => $meta_query, ‘posts_per_page’ => 10, ‘orderby’ => ‘date’, … Read more

Insert wp_query after the_content with plugin (filter the_content won’t work)

You should remove your hook before query. function wpse_288691_add_query_after_content( $content ) { $ouptut=””; remove_filter( ‘the_content’, ‘wpse_288691_add_query_after_content’ ); // Do your *** WP_Query *** and assign result to $ouptut. // Reset query by executing `wp_reset_query`. add_filter( ‘the_content’, ‘wpse_288691_add_query_after_content’ ); return $content . $ouptut; } add_filter( ‘the_content’, ‘wpse_288691_add_query_after_content’ ); Do not echo anything inside the filter, only … Read more