wordpress taxonomy query posts
See Taxonomy Parameters documentation – there is include_children parameter, which you can set to false in your taxonomy query.
See Taxonomy Parameters documentation – there is include_children parameter, which you can set to false in your taxonomy query.
Start by cleaning up your code; $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 3, ‘order’ => ‘asc’ ); $home_shows = new WP_Query($args); //setup your loop here if( $home_shows->have_posts() ): while( $home_shows->have_posts() ): $home_shows->the_post(); //fetch featured image if exists if ( has_post_thumbnail() ) { the_post_thumbnail(array(486,226)); } //fetch content the_content(); //etc… endwhile; endif; What output do … Read more
I was going to create my own question and answer it, but this looks as good a place as any. The way I solved this, is by using $_SESSION. Keep in mind I am using infinite-scroll, so I can tell when the page is being fetched via ajax as opposed to being actually navigated to … Read more
<?php $all_books = get_terms( ‘history_books’ ); // Get all history book terms. $rand_book = $all_books[ array_rand( $all_books ) ]; // Select one at random. $related = get_posts( array( ‘posts_per_page’ => 5, ‘tax_query’ => array( array( ‘taxonomy’ => ‘history_books’, ‘terms’ => array( $rand_book->term_id ), ) ) ) ); ?> <h3> <a href=”https://wordpress.stackexchange.com/questions/104280/<?php echo get_term_link( $rand_book ) … Read more
If I understand you correctly, something like this should help you. global $wpdb; $results = $wpdb->get_results( “SELECT post_author, SUM(comment_count) as comments FROM {$wpdb->posts} WHERE post_type=”post” AND post_status=”publish” GROUP BY post_author ORDER BY comments DESC LIMIT 10″); This will return you 10 authors of most commented posts (with highest sum of comments count of each post … Read more
Separate the posts in two different arrays, then loop over both separately: $columns = array ( ‘first’ => array (), ‘second’ => array () ); $first_column = array( 1, 3, 4, 5, 6, 7 ); // separation foreach ( $the_query->posts as $index => $post ) { if ( in_array( $index + 1, $first_column ) ) … Read more
You write the wrong code $paged = get_query_var(‘paged’) ? get_query_var(‘paged’) : 1; $args = array(‘posts_per_page’ => ‘5’, ‘paged’ => $paged, ‘tax_query’ => array( array(‘taxonomy’ => ‘news-categories’, ‘field’ => ‘slug’, ‘terms’ => ‘cbs-news’) ) ); You can also take help in WP_Query
If you have 8 categories, you need 8 queries. To improve your code use WP_Query instead of query_posts: <?php $categories = get_categories(); if ( ! empty($categories) ) { ?> <ul class=”tabs”> <?php foreach ($categories as $c ) { ?> <li> <a href=”#tab<?php echo $c->term_id; ?>”> <img src=”<?php bloginfo(‘template_directory’); ?>/images/logo-<?php echo $c->slug; ?>.png” alt=”<?php echo $c->name; … Read more
get_the_date depends on the global $post variable. It is a bit hard to tell that that is the case but if you look at the source for get_the_date you’ll see that it uses get_post and it assumes $post if no other parameters are given. Your code never sets that global $post variable except for when … Read more
Before answer I want to say that your code is not really wrong but can be improved: why run 2 queries when you can run only one? caller_get_posts is deprecated, use ignore_sticky_posts, instead get_terms has not title_li nor show_count argument. Moreover $taxonomy is the first argument and do nothing in the $args array (second argument). … Read more