Chaining Taxonomy Queries

Use get_categories to return the terms in each taxonomy then loop through each getting the posts. $args = array( ‘taxonomy’ => ‘meal_time’ ); $meal_times = get_categories( $args ); foreach ( $meal_times as $meal ) { echo ‘<h3 class=”meal-title”>’ . $meal->cat_name . ‘</h3>’; //Shows the term name as the title then loops through courses $child_args = … Read more

Displaying member join date on page

You can use the WP_User_Query class to query on user meta, however, your specific example of querying for a list of users with a join date matching a specific month and from any year requires a query more complex than what you can do out of the box with the WP_User_Query class. First, it’s important … Read more

loop inside a loop : search for posts in the same category

the_ID() prints the current post’s ID. You need to use get_the_ID() to return it. Also, get_the_category returns an array of category objects – one foreach category term the post belongs to. The ‘category’ attribute expects a category term ID. So you need to pick a category object, then obtain its ID: $cats = get_the_category(); $cat_obj … Read more

Avoid WP_Query’s duplicate posts with taxonomies

Pass the post ID from the first query as a post__not_in parameter to exclude it from the second query. $nature_loop_1 = new WP_Query( array ( ‘category_name’ => ‘nature’, ‘tax_query’ => array ( array ( ‘taxonomy’ => ‘highlight’, ‘field’ => ‘slug’, ‘terms’ => ‘sidebar-highlight’, ‘operator’ => ‘IN’ ) ), ) ); $exclude = $nature_loop_1->post->ID; $nature_loop_2 = … Read more

how to get the post id in the option tag

$post->id needs to be $post->ID You can also use get_the_ID() Since your calling setup_postdata() you need to call wp_reset_postdata() after your foreach loop. You also need to echo the value of $options somewhere. foreach( $myposts as $post ) : setup_postdata($post); $options .= ‘<option>’; $options .= ‘<option value=”‘.$post->id.'”>’; $options .= get_the_title(); $options .= ‘</option>’; echo $options; … Read more

Exclude current post ID from loop in sidepbar.php

First, do not use query_posts() for secondary loops. The query_posts() function is intended only to modify the primary loop query. Use WP_Query() or get_posts() for secondary loop queries. Also, showposts is deprecated. Use posts_per_page instead. Let’s use WP_Query(), as it will be the most analogous to your current implementation: <?php // First, let’s eliminate some … Read more

How to separate each individual blog post?

You can do that entirely with CSS, almost no PHP coding required… try something like this: <div id=”services”> <?php if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post(); ?> <div id=”post-<?php the_ID(); ?>” <?php post_class(); ?>> <?php the_content(); ?> </div> <?php endwhile; ?> <?php endif; ?> </div> … that way, each … Read more