How to sort category by custom field value

Your question it make sense to me my friend but the get_categories don’t have the option to order by “meta_value_num” and then order by custom fields. What you can do is order after you get the array using the usort php function: $all_subcategories = array(‘parent’ => $categoryID); $categories = get_categories( $all_subcategories ); function order_categories($a, $b) … Read more

Ordering Posts Type A by Custom Fields of related Post Type B

This works. The filters are tied to a custom ‘orderby’ term and removed after the query. $args = array( ‘post_type’ => ‘artworks’, ‘posts_per_page’ => -1, ‘no_found_rows’ => true, ‘order’ => ‘ASC’, ‘orderby’ => ‘artist_name_artwork_title’, ); add_filter(‘posts_join’, ‘name_join’, 10, 2 ); add_filter(‘posts_orderby’, ‘orderby_artist_name_artwork_title’, 10, 2); // query $wp_query = new WP_Query( $args ); remove_filter(‘posts_join’, ‘name_join’, 10 … Read more

Custom WP Query from meta_value stored as serialised array

If you’re inside the while loop, use get_the_ID(). // returns an array as this is a multicheck field in Magic Fields 2 if(get_post_meta(get_the_ID(), ‘services’, true)){ $services = get_post_meta(get_the_ID(), ‘services’, true); $services = maybe_unserialize($services); // foreach item in the array foreach ($services as $service) { if ( sanitize_title($service_title) == sanitize_title($service) ) { echo ‘<p>’ . esc_attr($service) … Read more

How to use Meta Value Compare in WP_Query For Max and Min numbers

This looks right, I have very similar code that works as expected: function price_query_test() { update_post_meta( 7, ‘_price’, 10 ); update_post_meta( 12, ‘_price’, 20 ); update_post_meta( 18, ‘_price’, 30 ); update_post_meta( 72, ‘_price’, 40 ); $test = new WP_Query( array( ‘post_type’ => ‘page’, ‘meta_query’ => array( array( ‘key’ => ‘_price’, ‘value’ => array( ’10’, ’25’ … Read more

Ordering by meta_value AND date NOT WORKING with wp_query

You have to use the posts_orderby filter to do this at the mo, eg function wpse159469_posts_orderby( $orderby, $query ) { return implode( ‘ DESC,’, explode( ‘,’, str_replace( array(‘ ASC’, ‘ DESC’ ), ”, $orderby ) ) ) . ‘ DESC’; } then around your query: add_filter( ‘posts_orderby’, ‘wpse159469_posts_orderby’, 10, 2 ); $query = new WP_Query( … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)