Custom Queries – Child Categories not showing up

category__and is exclusive, so it will not work for your application, if you use tax_query and setup your query as follows, it should work: $args = array( ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘id’, ‘terms’ => $city, //’include_children’ is true by default ), array( ‘taxonomy’ => ‘category’, //may need … Read more

How to get only one category of custom post type?

Never use query_posts! Use get_posts() or new WP_Query() instead. I think this will work however: $today = date(“Y/m/j”); $args = (array( ‘post_type’ => ‘event’, ‘posts_per_page’ => 10, ‘orderby’ => array( ‘wpse_meta_query_name’ => ‘ASC’, ‘post_title’ => ‘DESC’ // optional second orderby paramater ), ‘meta_query’ => array( ‘wpse_meta_query_name’ => array( // give the meta query arguments a … Read more

How to get the list of posts in a static page other than front page?

The way I retrieve posts on my blog is to use the following: <?php $recentPosts = new WP_Query(); $recentPosts->query(‘showposts=5&cat=CAT_ID_GOES_HERE’); while($recentPosts->have_posts()): $recentPosts->the_post(); ?> Then you would go and create the code to control the display of each post. So for a really simple example: <h1 class=”title”><a href=”https://wordpress.stackexchange.com/questions/3170/<?php the_permalink(); ?>”><?php the_title(); ?></a></h1> Then at the end of … Read more

How to query ‘posts_per_page’ to display a different blog posts index template?

You can control what template loads for any type of query via the Template Filters. Here’s an example using home_template that checks if posts_per_page is equal to 1, and loads single.php in that case. function wpd_home_template( $home_template=”” ){ if( get_option( ‘posts_per_page’ ) == 1 ){ $home_template = locate_template( ‘single.php’, false ); } return $home_template; } … Read more

query posts in wordpress

There is no term_id parameter. You need a tax_query. $args = array( ‘post_type’ => ‘my_post’, ‘posts_per_page’ => 6, ‘tax_query’ => array( array( ‘taxonomy’ => ‘yourtaxname’, ‘field’ => ‘id’, ‘terms’ => 1 ) ) ); $query = new WP_Query( $args ); Notice that I’ve use new WP_Query and not query_posts. Don’t use query_posts. Doing the above … Read more

Problem with single-page for my custom post

Your code looks sound, so you should have a look at the code in your single.php template, as I suspect that there is something wrong in that template to why nothing is displayed. You should set debug to true in wp-config.php. This should help you locate your problem Secondly, your single-posttype.php is wrongly named. Your … Read more

Two posts in same div – WP loop

This is really just a matter of logic. You need to conditionally print the div markup. The counter in $wp_query will let you chose every second post. if (have_posts()) { echo ‘<div class=”posts-wrapped”>’; while (have_posts()) { the_post(); if (0 !== $wp_query->current_post && 0 === $wp_query->current_post%2 ) { echo $wp_query->current_post.'</div><div class=”posts-wrapped”>’; } the_title(); echo ‘<br />’; … Read more

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