I got problem of my pagination in category pages >>
I made a category taxonomy for my CPT and when I add posts and posts goes to page 2 .. the page 2 got a ERROR not found
<?php
// ==== Query Dynamic Options ====//
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'portfolio',
'post_status' => 'publish',
'posts_per_page' => 9,
'paged' => $paged,
'order' => 'DESC',
'orderby' => 'ID',
'taxonomies' => 'portfolio-categories',
);
$the_query = new WP_Query( $args );
if you wanna see more code that will helps u to help me ask it for me I will capture it
Related
I was searching for this but didn't find the solution. I am getting posts orderby title but some posts need to come first so I added a custom field which meta_key is display_postion and the values for this fields are numbers i.e. 1,2,3. So how do I achieve this, below is my current code.
$args = array(
'post_type' => 'products',
'order' => 'ASC',
'orderby'=> 'title',
'post_status' => 'publish',
'posts_per_page' => -1,
'paged' => $paged
;
$wp_query = new WP_Query( $args );
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts()) : $wp_query->the_post();
Adding meta_value_num to an orderby array and referencing 'display_position' in the meta_key field should do the trick:
$args = array(
'post_type' => 'products',
'order' => 'ASC',
'orderby' => array(
'meta_value_num' => 'ASC',
'title' => 'ASC'
),
'post_status' => 'publish',
'posts_per_page' => - 1,
'paged' => $paged,
'meta_key' => 'display_position'
);
$wp_query = new WP_Query($args);
if ($wp_query->have_posts()):
while ($wp_query->have_posts()):
$wp_query->the_post();
See documentation for Order and Orderby parameters for WP_Query.
In a Wordpress page template, I set up a WP custom query which queries a custom post type named "recipe" AND the regular posts as below. This works, but 'orderby => 'date' in there doesn't work: The page first lists the regular posts ordered by date, then the recipes by date. But I need ALL of them together (i.e. mixed) ordered by date.
Here's the definition of my custom query:
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$number_of_posts = get_option('posts_per_page', 12);
$args = array(
'post_type' => array('recipe', 'post'),
'post_status' => 'publish',
'posts_per_page' => 12,
'orderby' => 'date',
'order' => 'ASC',
'paged' => $paged
);
$my_loop = new WP_Query($args);
[...followed by the loop...]
I am grateful for any hints what I can do to achieve the desired ordering.
I found a solution myself:
It works when I add remove_all_filters('posts_orderby'); before the custom query is defined. Obviously this resets any other ordering and allows the 'orderby' => 'date' to function as expected. Complete code:
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$number_of_posts = get_option('posts_per_page', 12);
remove_all_filters('posts_orderby'); // ADDED
$args = array(
'post_type' => array('recipe', 'post'),
'post_status' => 'publish',
'posts_per_page' => 12,
'orderby' => 'date',
'order' => 'ASC',
'paged' => $paged
);
$my_loop = new WP_Query($args);
[...]
Q1. what template file are you using?
The query below successfully merges the 2 post types together by date.
<?php
$args = array(
'post_type' => array('my_custom_post_type', 'post'),
'posts_per_page' => -1,
'order' => 'DESC',
'orderby' => 'date',
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post(); ?>
// loop your content here
<?php include(locate_template('templates/content.php')); ?>
<?php
}
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
?>
So, I tried all the "add_filter" things on the whole web to get this right but it doesn't work! It always shows me more than 1 post. What's wrong with my code? Latest WP-Version 4.1.1 and no plugins installed.
Here is the code:
<?php
$sticky = get_option('sticky_posts');
if ( !empty($sticky) ) {
$args = array(
'post__in' => $sticky,
'orderby' => 'date',
'order' => 'ASC',
'posts_per_page' => 1
);
$slider_query = new WP_Query( $args );
while ( $slider_query->have_posts() ) {
$slider_query->the_post();
?>
<div>
<!-- here we go -->
</div>
<?php
}
}
?>
Okay, I got it. This parameter is missing. Wordpress ignores "posts_per_page" by default for sticky posts.
$args = array(
'post__in' => $sticky,
'orderby' => 'date',
'order' => 'ASC',
'posts_per_page' => 1,
'ignore_sticky_posts' => 1
);
Wordpress doesn't play nice with posts_per_page and wp_query.
To fix it you have to use get_query_var, like so:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
And then in your wp_query() you do:
$args = array(
'post__in' => $sticky,
'orderby' => 'date',
'order' => 'ASC',
'posts_per_page' => 1,
'paged' => $paged
);
I have a page with the most rated posts.
I use WP-PostRatings and I use this code:
query_posts( array( 'meta_key' => 'ratings_average', 'orderby' => 'meta_value_num', 'order' => 'DESC' ) );
Is there a way to create pagination for pages?
I found something here Wordpress pagination with static pages , but it shows me in all pages, the newest posts, order by date (as in homepage)
Thank you!
To get pagination to work with query_posts() you need to add the $paged variable to your query:
$posts_per_page = 10;
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$query = array(
'meta_key' => 'ratings_average',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'posts_per_page' => $posts_per_page,
'paged' => $paged
);
query_posts( $query );
I'm using "the events calendar" plugin in WP which has a feature to allow event posts to show up as regular posts. I currently have a slider on my homepage that I would like to show featured events on. I was able to get it to show events as a "featured" category, but am having trouble ordering it by event date instead of publish date. This is what I have now.
Here is the original code just calling the specific category posts
<?php query_posts ('category_name=' .$slide.'&posts_per_page='.$bvkPP.'&paged='.$paged ); ?>
This is what I changed it to
<?php query_posts( array ('category_name=' .$slide.'&posts_per_page='.$bvkPP.'&paged='.$paged, 'orderby' => 'meta_value','meta_key' =>'_EventStartDate','order' => 'ASC',) ); ?>
This affectively ordered it by event date, but has overridden the category and is just calling for all events. Any thoughts on how to get just the specific category to show up?
Thanks!
I finally got it figured out. Here's what I came up with.
<?php query_posts( array(
'category_name' => $slide,
'posts_per_page' => $bvkPP,
'paged'=> $paged,
'orderby' => 'meta_value',
'meta_key' => '_EventStartDate',
'order' => 'ASC',
'eventDisplay'=> 'startDate',
'post_type'=> 'tribe_events' ) ); ?>
Thanks for the help!
get all event using your cat id.
<?php
$paged = ( get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1 );
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'tribe_events_cat',
'field' => 'id',
'terms' => '17' //17 is cat id
)
),
'eventDisplay'=>'startDate',
'post_type'=>'tribe_events',
'orderby'=>'meta_value',
'meta_key'=>'_EventStartDate',
'posts_per_page' =>10,
'paged' => $paged,
'order' => 'ASC',
);
query_posts($args);
while ( have_posts() ) : the_post(); ?>
//your code here for get title/content
<?php
endwhile;
wp_reset_query();
?>