How to sort a WP_Query by a custom field AND ALSO filter by a different custom field

to sort the posts by a meta field you need to have this field in meta_query and in orderby like this $query_args = array( ‘post_type’ => ‘MY_POSTTYPE_NAME’, ‘post_per_page’ => -1, ‘meta_query’ => array( ‘show_post_query’ => array( ‘key’ => ‘SHOW_POST’, ‘value’ => ‘1’ ), ‘MY_FIELD_NAME__order_by’ => array( ‘key’ => ‘MY_FIELD_NAME’, ‘type’ => ‘NUMERIC’, ‘compare’ => ‘NUMERIC’, … Read more

Include custom post type custom taxonomies in Categories widget

The widget class uses wp_list_categories() which supports all the parameters for get_terms() like taxonomy which you can use to make the widget lists categories in a taxonomy other than category. So your code would be: add_filter(‘widget_categories_args’, function( $params ) { // $params[‘post_type’] = array(‘post’, ‘recipe’); // post_type is not a standard parameter for get_terms() $params[‘taxonomy’] … Read more

Echo text using is_tag

That’s not what is_tag does: Determines whether the query is for an existing tag archive page. https://developer.wordpress.org/reference/functions/is_tag/ is_tag and other functions such as is_search etc don’t tell you anything about a post, they tell you if you’re on a search archive, or a tag archive, etc So is_tag is true on example.com/tag/example but would be … Read more

How to get dropdown instance value in WordPress custom Widget

The cat_drop setting is empty because your drop-down menu, or the select field doesn’t have the proper name value, so PHP isn’t receiving the selected option/value. So to fix the issue, just add the proper name value to the select field: <!– Wrapped for brevity. –> <select name=”<?php echo $this->get_field_name( ‘cat_drop’ ); ?>” id=”<?php echo … Read more

WP Job Manager plugin – Listing only the twelve job categories on frontpage order by jobs they have

Edited: This is a much simpler version of what you are looking to do. You don’t need WP_Query(). You can use a foreach loop and an iterator: <?php echo ‘<ul class=”job-category-list”>’; // Get the terms and order them by count in descending order. $terms = get_terms( [ ‘taxonomy’ => ‘job_listing_category’, ‘orderby’ => ‘count’, ‘order’ => … Read more