Order taxonomy terms in alphabetical order
Since 4.5.0, taxonomies should be passed via the ‘taxonomy’ argument in the $args array: $terms = get_terms( array( ‘taxonomy’ => ‘projets-location’, ‘orderby’ => ‘name’, ‘order’ => ‘DESC’ ) );
Since 4.5.0, taxonomies should be passed via the ‘taxonomy’ argument in the $args array: $terms = get_terms( array( ‘taxonomy’ => ‘projets-location’, ‘orderby’ => ‘name’, ‘order’ => ‘DESC’ ) );
AFAIK there’s no way to achieve that within a single WP_Query, so you’ll have to first get a list of term_ids which have a different year than the one in question. I think with the following you’ll come quite close. (don’t have a env to test right away) $other_years_terms = get_terms( ‘taxonomy’ => ‘vintage’, ‘meta_key’ … Read more
You can use before and after, see date arguments. $args = array( ‘posts_per_page’ => ‘-1’, ‘date_query’ => array( array( ‘after’ => ‘December 31st, 2015’, // i.e., 2016+. ‘before’ => ‘January 1st, 2018’, // i.e., before 2018. ), ), ); $query = new WP_Query( $args ); Based on an article written by one of the date … Read more
Inside the loop you can use $the_query->current_post to get the index of the post currently being displayed. You can then check if the index is an odd or even number and conditionally add the class. Example: if ( 1 === $the_query->current_post % 2 ) { echo ‘class=”switchable”‘; }
Your query looks OK, so I doubt that it will cause any problems. But then… Let’s take a look at your loop: if ($mainPosts->have_posts()) { while ($mainPosts->have_posts()) { $postItemImage = the_post_thumbnail_url(); … echo “…”; } } First of all you don’t have any else in there, so there is no point in this if. But … Read more
You might try adding a second meta_query that would look for anything without the meta key: $args = array( ‘post_type’ => ‘agenda’, ‘paged’ => $paged, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘datum_event’, ‘value’ => date(‘Ymd’), ‘compare’ => ‘<=’ ), array( ‘key’ => ‘datum_event’, ‘meta_compare’ => ‘NOT_EXISTS’, ‘value’ => ‘placeholder’ ), ), ); … Read more
The error says it all. You are trying to get property ID of non-object. That means that the $post var is not an object. You can get current post ID within a WordPress loop using get_the_ID(), but actually you don’t need it in this case (see explanation below). if ( $query->have_posts() ) { while ( … Read more
Two bits of advice: Most importantly, database query performance hinges on how many rows match the query, not how many rows you want. Even if you’re only asking for 5 posts, the database could have to query and sort a million results in order to give you those 5. Say I gave you a 100,000 … Read more
Maybe you’re looking for the post__in parameter in WP_Query. $query = new WP_Query(array( ‘post__in’ => array(23,18,2,199,6,8) ); And then: while ( $query->have_posts() ) { $query->the_post(); /* post loop */ } Take a look at the docs. =D For public queries: post__in is not public queryable by default, so you can just validate and copy $_GET[‘post__in’] … Read more
Use wp_reset_postdata() function after while loop to reset custom wp_query as shown in following code so that it will not break other wordpress loop. <?php // Create and run custom loop $custom_posts = new WP_Query(); $custom_posts->query(‘post_type=jobs&posts_per_page=8’); while ($custom_posts->have_posts()) : $custom_posts->the_post(); ?> <li><a href=”https://wordpress.stackexchange.com/questions/98851/<?php the_permalink(); ?>”><?php the_title(); ?></a></li> <?php endwhile; ?> <?php wp_reset_postdata(); ?> For more … Read more