Use WP_Query with have_posts()?

global $wp_query; $original_query = $wp_query; $wp_query = null; $wp_query = new WP_Query( $args ); if ( have_posts() ) : while ( have_posts() ) : the_post(); the_title(); the_excerpt(); endwhile; else: echo ‘no posts found’; endif; $wp_query = null; $wp_query = $original_query; wp_reset_postdata(); http://codex.wordpress.org/Function_Reference/wp_reset_postdata

WP_query to get the first two latest posts, then another loop to get the next three

Run one wp_query for post_per_page = 2 and get the IDs of these 2 posts in an array to be excluded in the next 3 posts needed <?php // The Query $next_args = array( ‘post_type’ => ‘<your_post_type>’, ‘post_status’ => ‘publish’, ‘posts_per_page’=>2, ‘order’=>’DESC’, ‘orderby’=>’ID’, ); $the_query = new WP_Query( $args ); // The Loop if ( … Read more

WP_Query: query posts by ids from array?

You have to use post__in (double underscore) argument, instead of post_in: echo print_r($rel); // Array ( [0] => 63 [1] => 87 ) $args = array( ‘post_type’ => array( ‘post’ ), ‘orderby’ => ‘ASC’, ‘post__in’ => $rel ); $loop = new WP_Query( $args ); If you are unsure why an argument is not working, copy … Read more

Using OR conditions in meta_query for query_posts argument

Use ‘relation’ => ‘OR’ as in the Codex example below: $args = array( ‘post_type’ => ‘product’, ‘meta_query’ => array( ‘relation’ => ‘OR’, /* <– here */ array( ‘key’ => ‘color’, ‘value’ => ‘blue’, ‘compare’ => ‘NOT LIKE’ ), array( ‘key’ => ‘price’, ‘value’ => array( 20, 100 ), ‘type’ => ‘numeric’, ‘compare’ => ‘BETWEEN’ ) … Read more

Function in array as arguments for WP_Query

I suspect the problem is coming from $MyCustomField which you enter as such in: ‘terms’ => array( $MyCustomField ), The query consider it as only one value: ‘64,72’, a string. So try: $MyCustomFieldValues = array_map( ‘intval’, explode( ‘,’, $MyCustomField ) ); This will also ensure your values are integers. Then: ‘terms’ => $MyCustomFieldValues,

Make loop display posts by alphabetical order

To display posts in descending alphabetical order add this to your args array (taken from the wp codex) ‘orderby’ => ‘title’, ‘order’ => ‘DESC’, To display posts in ascending alphabetical order just switch DESC to ASC. So the whole thing would look like: $args = array( ‘orderby’ => ‘title’, ‘order’ => ‘DESC’, ); $query = … Read more

Search custom taxonomy term by name

// We get a list taxonomies on the search box function get_tax_by_search($search_text){ $args = array( ‘taxonomy’ => array( ‘my_tax’ ), // taxonomy name ‘orderby’ => ‘id’, ‘order’ => ‘ASC’, ‘hide_empty’ => true, ‘fields’ => ‘all’, ‘name__like’ => $search_text ); $terms = get_terms( $args ); $count = count($terms); if($count > 0){ echo “<ul>”; foreach ($terms as … Read more

paginate_links() adds empty href to first page and previous link

Have you tried specifying the base and format arguments for paginate_links()? It assumes the default values of: ‘base’ => ‘%_%’, ‘format’ => ‘?page=%#%’, Your base should be something like /parent-page/child-page/%_%; then the first page link will be to /parent-page/child-page/, and subsequent links will follow the format /parent-page/child-page/?page=3 (example for page 3). In the base, the … Read more

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