Articles of wp query

Custom wp_query – I'm getting 'all' post, not the specific post in the query

Get all post from today, that are of post type ‘product’ and are in the taxonomy of ‘productType’ as ‘Indica’ and in the taxonomy of ‘locationCity’ as ‘Los Angeles’ — However, I get ‘all’ the post with no regards to the query params of the custom taxonomies. // args $today = getdate(); $indicaArgs = array( […]

Post archive for certain post format

I am using the following code for a custom archive of all posts: $taxonomy = ‘category’; $param_type = ‘category__in’; $term_args = array( ‘orderby’ => ‘slug’, ‘order’ => ‘ASC’ ); $terms = get_terms($taxonomy,$term_args); if ($terms) { foreach( $terms as $term ) { $args = array( “$param_type” => array($term->term_id), ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => […]

How to overwrite orderby with add_query_var

So I would like to have an archive that displays its posts in a random order. <?php $query = new WP_Query($query_string.”&orderby=rand”); ?> But also then if the user chooses they can order the posts differently by clicking a button. <?php $sort_date = add_query_arg(array(‘orderby’=>’date’,’order’=>’asc’)); $sort_name = add_query_arg(array(‘orderby’=>’title’,’order’=>’asc’)); ?> <div class=”sort”> Sort by: <a href=”<?php echo $sort_date; […]

Issue with data array format

I am trying to fetch a record of date from table booking_history with bellow code but the result array not displaying any record from start_date column. when i echo the query query displaying value accurately. $booking_date = $_POST[‘booking_date’]; $post_id = $_POST[‘post_id’]; echo $check_cust_query = “SELECT start_date FROM `”.$wpdb->prefix.”booking_history` WHERE start_date='”.$booking_date.”‘ AND post_id='”.$post_id.”‘”; $results_check_cust = $wpdb->get_results […]

Sorting posts by Multiple custom fields in defined order

I’m currently sorting some posts out by custom fields ‘role’ and ‘surname’, using the following: function customorder($orderby) { return ‘mt1.meta_value DESC, mt2.meta_value ASC’; } $args = array( ‘post_type’ => ‘staff’, ‘meta_key’ => ‘role’, ‘meta_query’ => array( array( ‘key’ => ‘role’ ), array( ‘key’ => ‘surname’, ), ) ); add_filter(‘posts_orderby’,’customorder’); $query = new WP_Query( $args ); […]

list posts of two post types in a single template

I have two post types. One is post & other one is event. Both sharing same categories & tags. I am listing the posts by archive.php. Now I am listing the posts as general by two different templates like archive.php / archive-event.php. But now I want to list them in a single template with mixing […]

Custom WP_Query not working correctly

OK, So I have created a custom WP_Query that gets the post_type post and outputs it as a styled list. It works well and outputs the styled list but then underneath it displays all the posts again but in a completely different format (unstyled). <?php // get all post types $args = array ( ‘post_type’ […]

WP order ASC in custom author loop

My current author list shows authors with posts only, but its not ordered by ASC and its not working. Any ideas? <ul class=”authorlist”> <?php // displays all users with their avatar and their posts (titles) $blogusers = get_users_of_blog(); if ($blogusers) { foreach ($blogusers as $bloguser) { $user = get_userdata($bloguser->user_id); $args=array( ‘author’ => $user->ID, ‘post_type’ => […]

How to show subcategories using loop?

i am using wp_list_categories(‘child_of=54&title_li=’) method to display all the subcategories, but it is showing only one, how can i use it with loop to show all the subcategories properly.

WP_Query: Posts within category OR custom post type

I don’t like to bother you guys, but this is already driving me nuts. I have a legacy post model within a specific category called ‘listas-2’ that used shortcodes to show some fancy things. Now I have created a custom post type named ‘lista’ that does the same thing but way better, using post_metas. The […]