Articles of wp query

Next/Prev posts on same page

Hello WordPress Users, I’m stuck with a problem building my wordpress website and I can’t figure out what to do about it. Currently I’m showing 2 posts form the category ‘News’ at the page ‘News’. At the bottom of this page I want a Prev/Next button that shows the next or previous 2 posts from […]

Why WP_Query::is_date() returns false when 'date_query' argument is set?

WordPress 3.7 introduced ‘date_query’ argument for WP_Query. That’s pretty useful and allow very complex date-based queries, however something strange happen when using WP_Query conditional methods on query using that argument. Example: $args = array( ‘tax_query’=> array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => ‘uncategorized’ ), array( ‘taxonomy’ => ‘post_tag’, ‘field’ […]

How to get a meta value from all post

I searched for a while but I didn’t find any solution. I used the functions listed here. It outputs something like this: Array ( [0] => 15 [1] => 30 [2] => 50 ) But I want something like this: Array ( [post_id_1] => 15 [post_id_2] => 30 [post_id_3] => 50 ) And this is […]

WP_Query on custom field and order results

I have the following WP_Query: $custom_query_args = array( ‘post_type’ => ‘mcg_event’, ‘posts_per_page’ => -1, ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘event_status’, ‘value’ => ‘archived’, ), array( ‘key’ => ‘event_start_date’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ) ), ); I’m looking to do 2 things: only fetch events that have an event_status of […]

category__in not working on custom post type

Can’t get my WP_Query loop to work, cannot figure out why category__in won’t work. Just want to pull certain categories FROM my custom post type $args = array( ‘post_type’ => ‘bbt’, ‘category__in’ => array(90,89) ); $loop = new WP_Query($args); when I use echo $loop->found_posts; it does returns 0, BUT I have 2 posts in total […]

Pagination when using wp_query?

<!– query –> <?php $paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : 1; $query = new WP_Query( array( ‘category_name’ => ‘investor-news’, ‘posts_per_page’ => 2, ‘paged’ => $paged ) ); ?> <?php if ( $query->have_posts() ) : ?> <!– begin loop –> <?php while ( $query->have_posts() ) : $query->the_post(); ?> <h2><a href=”<?php […]

Front End Sorting Questions

Please bare with me as I am self taught and trying to learn as much as possible. I am going to try and provide as much information as possible that I have learned from researching this problem. My Goal/The Problem: Allowing readers to sort a category of posts using either a clickable link or drop […]

Trouble Making WP_Query paged

I’m using the query below in the index.php file as the main query, whenever I try to go to the 2nd page I get a 404 error, I tried using posts_per_page but to no avail. <?php $args = array( ‘post_type’ => array( ‘post’, ‘videos’, ‘music’ ), ‘tax_query’ => array( array( ‘taxonomy’ => ‘content’, ‘field’ => […]

Get first post from wp_query

How can I get the first post from a WP_Query result? $connected = new WP_Query( array( // Arguments )); // This doesn’t work.. echo $connected[0]->post_name;

Use 'parse_query' filter to show posts that from multiple criteria

I am trying to filter the Posts page in the WordPress admin to show posts that meet the criteria for “A” -or- the criteria for “B”. I’ve scoured documentation and can’t find a good way to do this. Details: I’ve scoped user roles so that authors can only edit their own posts. However, I’ve added […]