Query posts by category AND custom field, then ORDERBY another custom field – help!
I ran your query on my local workstation. It looks like there is a typo: You should have $wpdb->postmeta.meta_value not $wpdb->wpostmeta.meta_value (used twice).
I ran your query on my local workstation. It looks like there is a typo: You should have $wpdb->postmeta.meta_value not $wpdb->wpostmeta.meta_value (used twice).
Have a look here for the solution (code needs optimizing, but it works): Help to condense/optimize some working code
And I should have done some searching before asking. Looks like hooking the query might be the best way of doing this. Here’s a good answer from StackOverflow with practically the same question.
Hi @Ryan Long: You have two problems: You need to wrap the result of date( ‘Y-m-d’ , $newdate ); in a SQL DATE() function, and You define $ayearago outside of the filter_where() function so it’s not in scope within the function. You need to move the code that sets $ayearago into the filter_where() function like … Read more
query_posts() ALWAYS displays something? No it doesn’t at least not for me, i’ve tried the code you posted inside my child theme and was unable to reproduce the issue described. Firstly, i tried… while ( have_posts() ) : the_post(); ?> <!— DO NOTHING ! –> <?php endwhile ?> ..and got nothing, so i then tested.. … Read more
You can use meta_query to get only posts with display_submenuexpositions = true and order them by order_submenuexpositions. $args = array( ‘orderby’ => ‘meta_value’, ‘meta_key’ => ‘order_submenuexpositions’, ‘meta_query’ => array( array( ‘key’ => ‘display_submenuexpositions’, ‘value’ => ‘true’, ‘compare’ => ‘LIKE’ ) ) ); $query_posts( $args );
A while back i posted a simple function that gets latest post in a certain category: function get_lastest_post_of_category($cat){ $args = array( ‘posts_per_page’ => 1, ‘order’=> ‘DESC’, ‘orderby’ => ‘date’, ‘category__in’ => (array)$cat); $post_is = get_posts( $args ); return $post_is[0]->ID; } So once you have that function you can use use WP_Query or query_posts and using … Read more
You will need to set a Static Page as your front page, create and assign a PHP Template for that page, and stack multiple Queries in the template to search out your required categories and display them. Here is one, you might have many: // get the last post (any date) from ‘Featured’ category $featured … Read more
Maybe take a look inside the 2010 theme that comes packaged with WP, index.php shows a call to a loop file: <?php get_template_part( ‘loop’, ‘index’ ); ?> so you could (well this is how i would do it, cos i think it looks neater, but you could use multiple loops) create 2 new loop files … Read more
As @TheDeadMedic said, you’ve to work like that. in the default loop like: while( have_posts() ) : the_post endwhile; in this case, the loop is running with the default $wp_query variable. But as you are running custom queries, you need to use while( $query_obj->have_posts() ) : $query_obj->the_post(); like that But while logged in and logged … Read more