WP_Query order by two values

I believe this is what your looking for. $q = new WP_Query( array( ‘meta_query’ => array( ‘relation’ => ‘AND’, ‘state_clause’ => array( ‘key’ => ‘state’, ‘value’ => ‘Wisconsin’, ), ‘city_clause’ => array( ‘key’ => ‘city’, ‘compare’ => ‘EXISTS’, ), ), ‘orderby’ => array( ‘city_clause’ => ‘ASC’, ‘state_clause’ => ‘DESC’, ), ) ); WP_Query

Using get_posts to get posts based on a checkbox value with Advanced Custom Fields

OK, I found the answer here: WP Query post meta value Turns out you have to use the serialize php function due to how wordpress stores arrays in the database. function get_city_jobs() { $city = ($_GET[‘city’]); $city = trim(ucfirst($city)); $args = array( ‘post_type’ => ‘careers_post_type’, ‘numberposts’ => -1, ‘meta_query’ => array( array( ‘key’ => ‘city’, … Read more

get_posts custom field

If you want to use post meta for setting which posts are displayd on the front page, then I would recommend saving the setting with a separate meta_key. So instead of pushing it to the your_fields save it with its own key. This means modifying your metabox content to have something like this, <input type=”checkbox” … Read more

display posts of custom post type with custom taxonomy

I would use “get_the_terms” to get the terms related to the post instead of “get_terms”, here is a quick suggestion (not tested) $args=array( ‘post_type’=>’tour_package’, ‘post__not_in’ => array(get_the_ID()), ‘posts_per_page’=> 5, ‘caller_get_posts’=>1,//handle sticky post but not in first ); $categories = get_the_terms( get_the_ID(),’tour_category’ ); if ($categories) { $category_ids = array(); foreach($categories as $individual_category){ $category_ids[] = $individual_category->term_id; } … Read more

Custom Category Walker with Image, Fallback to Most Recent Post in Category Image

The solution to the problem is that the tax_query needs to be an array of arrays. Thank you Sally CJ for the comment above, which also reminded me to $query->request. Here’s the total Walker for anyone for whom it’s useful: class List_Category_Walker extends Walker_Category { function start_el( &$output, $category, $depth = 0, $args = array(), … Read more

inserting content of 1 Post to in another with a template hierarchy

Yes, get_page_by_path() will return a post object or array on success, and not the post ID. $faq_post = get_page_by_path( $post_slug, OBJECT, ‘land’ ); // object $faq_post = get_page_by_path( $post_slug, ARRAY_A, ‘land’ ); // array So there is no need to make the custom new WP_Query call, and your code below is good: $faq_post = get_page_by_path( … Read more

How do you determine if a result in a search query is a post or a page?

That will only tell you if it’s a Post or a Page. What if it’s a category, tag, archive, or custom post type? Here’s how I’d write that, if you care. function xyz_get_post_type_name() { $wp_type = get_post_type( get_the_ID() ); switch ($wp_type) { case ‘post’ : $type_name=”Article”; break; case ‘page’ : $type_name=”Web Page”; break; case ‘quote’ … Read more

Show menus to one admin username

function hide_menu() { global $current_user; $current_user = wp_get_current_user(); $user_name = $current_user->user_login; //check condition for the user means show menu for this user if(is_admin() && $user_name != ‘USERNAME’) { //your code here } } add_action(‘admin_head’, ‘hide_menu’);