Articles of wp query

Pagination shows 404 after a certain number of pages

This issue is in my index.php (although i’m thinking about moving this code to home.php instead). I have a custom WP_Query which shows some posts per page, specifying post types (i have a custom type which the main query was not able to show). I have 42 posts atm (it’s the WordPress theme unit plus […]

I want to query posts in monthly basis

I have a page where I want to show Blog Posts on a monthly basis. And I want to show the post of the previous month if the current month has no posts. Something like the image given below. It is showing the posts of August because September has no post. here the code I […]

only delete post within query / for each statement (front end)

I am using this in my functions which I can use to delete the current page (custom post type called – bucket) and all it’s children: function delete_post(){ global $post; $deletepostlink= add_query_arg( ‘frontend’, ‘true’, get_delete_post_link( get_the_ID() ) ); if (current_user_can(‘edit_post’, $post->ID)) { echo ‘<span><a class=”post-delete-link” onclick=”return confirm(\’Are you sure to delete?\’)” href=”‘ . $deletepostlink . […]

Hide post if matches current month and year

I have here a query which display if it matches the current month and year published. The second one need to be the reverse one for the first code which display all post except the one that match the current month and year. // CURRENT MONTH AND YEAR ONLY <?php $current_year = date(‘Y’, current_time(‘timestamp’)); $current_month […]

how to merge a WPQuery array with a PHP array and use the Loop to Output the result

I have a mostly normal WP_Query (getting 3 post types) for use on a Blog page. This works great. Client wants the Instagram images to be included and ordered by date. I have all the instagram code setup and working fine creating an separate array. The caveat is that I need to format this Instagram […]

Multiple custom fields for 'orderby' in 'WP_Query'

I am trying to order blog posts by ‘city’ first and then order by ‘street_name’ within each city. I can’t seem to get the ‘street_name’ to display in alphabetical order. I am using WP_Query: <?php $args = array( ‘post_type’=> ‘property’, ‘meta_query’ => array( array( ‘relation’ => ‘AND’ , array( ‘meta_key’ => ‘city’, ‘orderby’ => ‘meta_value’, […]

wp_query display posts from same category of the post

On my post page I am trying to display list of other posts from the same category of the original post. So far I got this and this does not seem to work: <?php $args = array( ‘post_type’ => ‘article’, ‘posts_per_page’ => 5, ‘post__not_in’ => array( get_the_ID() ), ‘category’ => array( get_the_category() ), ‘meta_query’ => […]

Load more AJAX on WP Query

I am trying to get an AJAX WP Query loop to output 2 posts then use a ‘Load more’ button to load the next page of results. What is the best method to approach as not currently working? JS var ajaxRequest=function(){ var filter = $(‘#filter’); var page = 1; // What page we are on. […]

Category attribute not working in custom shortcode

I have the following function written, the issue is when I set the category in my shortcode it ignores it and shows all posts from the custom post type. So it only sort of works. /*————————————————————– ## Resources Shortcode ————————————————————–*/ function resources_query( $atts ) { extract(shortcode_atts(array( ‘category’ => ”, ‘per_page’ => -1, ‘orderby’ => ‘date’, […]

Order WP_Query by multiple fields, subtracting them from one another

I have two custom fields for each post, vote_up and vote_down. I know how to order by one of them, but I’m wondering how I can get the totals of both, subtract vote_down from vote_up and then display them according to the result of that calculation. Ideas?