$in_same_term = true
when using the get_next_post
and get_previous_post
functions, and the current post has several parent categories and several child catgeories:
– will the function pick the next/previous post only from the current posts parent categories or will it also consider child categories?
– if the post has several categories, let’s say: first, second and third category (both parent and child categories), will it choose a post from all 3 categories, or only from the first?
And if the current post has categories A and B, then will an other post that has the categories A and B have priority in the next/prev choice, even if its publish date falls further away than let’s say an other post, that has categories A and C?
And is there any difference in the choices of the functions in comparison, when using get_next_post
& get_previous_post
, get_adjacent_post
and get_{$adjacent}_post_where
?
However, get_previous_post () does return an object, and it can generate a link in absolutely all posts on the blog.
I have activated SAVEQUERIES to true in WP_config.php to be able to see the queries that are generated when the page is loaded, and I have painted one by one in phpMyadmin, but I have not been able to see that any of them have relation with pagination, but with plugins like Yoast Seo, or the related_post() just to mention some of them.
So, I’m completely lost, and I do not know where to start to look for to fix the issue.
BTW, I don’t use any rare or custom taxonomy, at least that I know of.
Any idea where I can start looking for or how to solve it?
Anyone else with the same problem as me?
Thanks in advance!
Note: I do not publish an url to check, because I do not think has nothing to do with my problem. I hope it’s not a problem.
]]>Thank you for your work on this amazing plugin.
I’m using WP 4.4.2 and Polylang 1.8.5, with a static Front Page and no custom permalinks structure.
I’m pretty sure there is a bug in the plugin, causing WP pagination functions get_next_post() , get_previous_post() and get_adjacent_post() return empty result when translation is disabled for the current Post Type in Polylang settings.
In file frontend/frontend-filters.php line 31-36 :
// rewrites archives, next and previous post links to filter them by language
foreach ( array( 'getarchives', 'get_previous_post', 'get_next_post' ) as $filter ) {
foreach ( array( '_join', '_where' ) as $clause ) {
add_filter( $filter.$clause, array( &$this, 'posts'.$clause ) );
}
}
This code adds an INNER JOIN clause to the SQL query used by WordPress (see the apply_filters in wp-includes/link-template.php line 1669) when searching adjacent post.
I understand the purpose of your code is to filter the adjacent post by language. Problem is that the INNER JOIN clause is added, even if the translation of this CPT is disabled in PLL settings. It cause the SQL query to return empty results because your join clause ‘pll_tr.object_id = ID’ can never be true.
I think wp_get_archives() may also be broken in the same context, but I didn’t test it.
Can you confirm the issue ? I hope you can solve it in next release, but I know PLL is a lot of work.
Bests regards,
Pierre Dargham
https://www.ads-software.com/plugins/polylang/
]]>https://i.stack.imgur.com/QOiNk.jpg
It contains two rows, and every row has three columns. I want to show random posts from my WordPress database in this grid.
This is my code
`<div class=”row”>
<div class=”col-xs-12″>
<div class=”rst-mediagrid”>
<div class=”div”>
<?php
$args = array(
‘posts_per_page’ => 6,
‘offset’ => 0,
‘category’ => ‘2’,
‘category_name’ => ”,
‘orderby’ => ‘date’,
‘include’ => ”,
‘exclude’ => ”,
‘meta_key’ => ”,
‘meta_value’ => ”,
‘post_type’ => ‘post’,
‘post_mime_type’ => ”,
‘post_parent’ => ”,
‘author’ => ”,
‘post_status’ => ‘publish’,
‘suppress_filters’ => true
);
global $post;
$post = get_post($args);
$next_post = get_adjacent_post( true, ”, false, ‘taxonomy_slug’ );
?>
<div class=”rst-col rst-col-50″>
<div class=”rst-postpic”>
<?php echo get_the_post_thumbnail($post->ID); //latest post thumbnail ?>
</div>
</div>
<?php //endif; ?>
<div class=”rst-col rst-col-25″>
<div class=”rst-postpic rst-postvideo”>
<?php echo get_the_post_thumbnail($next_post->ID); ?>
</div>
</div>
<div class=”rst-col rst-col-25″>
<div class=”rst-postpic”>
<?php echo get_the_post_thumbnail($next_post->ID); ?>
</div>
</div>
<div class=”clear”></div>
</div>
<div class=”div”>
<div class=”rst-col rst-col-25″>
<div class=”rst-postpic”>
<?php echo get_the_post_thumbnail($next_post->ID); ?>
</div>
</div>
<div class=”rst-col rst-col-25″>
<div class=”rst-postpic rst-postvideo”>
<?php echo get_the_post_thumbnail($next_post->ID); ?>
</div>
</div>
<div class=”rst-col rst-col-50″>
<div class=”rst-postpic”>
<?php echo get_the_post_thumbnail($next_post->ID); ?>
</div>
</div>
<div class=”clear”></div>
</div>
</div>
</div>
</div>`
The above code repeats the same image that I want to show thumbnails for in a perfect order, like the first row has three columns, and the first column has the latest image second column has image of previous post and third column has image of previous of previous mean 3rd post from latest post and second row also has same things.
If you have better suggestion kindly tell me.
]]>https://i.stack.imgur.com/QOiNk.jpg
It contains two rows, and every row has three columns. I want to show random posts from my WordPress database in this grid.
This is my code
<div class=”row”>
<div class=”col-xs-12″>
<div class=”rst-mediagrid”>
<div class=”div”>
<?php
$args = array(
‘posts_per_page’ => 6,
‘offset’ => 0,
‘category’ => ‘2’,
‘category_name’ => ”,
‘orderby’ => ‘date’,
‘include’ => ”,
‘exclude’ => ”,
‘meta_key’ => ”,
‘meta_value’ => ”,
‘post_type’ => ‘post’,
‘post_mime_type’ => ”,
‘post_parent’ => ”,
‘author’ => ”,
‘post_status’ => ‘publish’,
‘suppress_filters’ => true
);global $post;
$post = get_post($args);$next_post = get_adjacent_post( true, ”, false, ‘taxonomy_slug’ );
?>
<div class=”rst-col rst-col-50″>
<div class=”rst-postpic”>
<?php echo get_the_post_thumbnail($post->ID); //latest post thumbnail ?>
</div>
</div>
<?php //endif; ?><div class=”rst-col rst-col-25″>
<div class=”rst-postpic rst-postvideo”>
<?php echo get_the_post_thumbnail($next_post->ID); ?>
</div>
</div><div class=”rst-col rst-col-25″>
<div class=”rst-postpic”>
<?php echo get_the_post_thumbnail($next_post->ID); ?>
</div>
</div><div class=”clear”></div>
</div>
<div class=”div”>
<div class=”rst-col rst-col-25″>
<div class=”rst-postpic”>
<?php echo get_the_post_thumbnail($next_post->ID); ?>
</div>
</div>
<div class=”rst-col rst-col-25″>
<div class=”rst-postpic rst-postvideo”>
<?php echo get_the_post_thumbnail($next_post->ID); ?>
</div>
</div>
<div class=”rst-col rst-col-50″>
<div class=”rst-postpic”>
<?php echo get_the_post_thumbnail($next_post->ID); ?>
</div>
</div>
<div class=”clear”></div>
</div>
</div>
</div>
</div>
The above code repeats the same image that I want to show thumbnails for in a perfect order, like the first row has three columns, and the first column has the latest image second column has image of previous post and third column has image of previous of previous mean 3rd post from latest post and second row also has same things.
If you have better suggestion kindly tell me.
]]>As shown here I have added the ‘8’ in the following for but it is not excluding category #8 posts from the navigation.
`// Don’t print empty markup if there’s nowhere to navigate.
$previous = ( is_attachment() ) ? get_post($post->post_parent) : get_adjacent_post(false, ‘8’, true);
$next = get_adjacent_post(false, ‘8’, true);
if (!$next && !$previous)
return;
$prevPost = get_previous_post(false, ‘8’);
$prevthumbnail = get_the_post_thumbnail($prevPost->ID, ‘thumbnail’);
$nextPost = get_next_post(false, ‘8’);
$nextthumbnail = get_the_post_thumbnail($nextPost->ID, ‘thumbnail’);`
Can someone please help me out in pointing out the mistake(s) I made above.
P.S. The thumbnail of posts from category 8 are being removed from the navigation but not the post though.
The site I’m using the above navigation on is https://wyrta.com/
]]>My not working code is:
<?php
$next_post = get_next_post(true);
if (!empty( $next_post )): ?>
<a href="<?php echo get_permalink( $next_post->ID ); ?>">prev</a>
<?php endif; ?>
If I delete ‘true’ it works
]]>I need to be able to choose which category is going to be used in next /previous posts.
Example:
For Post 1 use Category 1 only. (which will reach post 3 as next post, not Post 2).
I checked the function reference in WordPress codex and it can’t be done with the parameters of /get next post. You can only exclude certain categories, use the current category or specify a taxonomy.
I need to be able to specify the category of the next / previous post by myself.
My idea is to get the category current printed in the url.
I’m using the following code, where:
$categoryslug is the category slug printed in the url that I want to use to tell WordPress which category will be used in next / previous posts.
Code:
<?php $url = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; ?>
<?php if (false !== strpos($url,'?c')) : ?>
<div id="nav-portfolio">
<?php
$categoryurl = explode('/', $url);
$categoryslug = str_replace("?c=","",$curl);
?>
<div class="prev">
<?php
$prev_post = get_previous_post();
if (!empty( $prev_post )): ?>
<a href="<?php echo get_permalink( $prev_post->ID ); ?><?php echo $categoryurl[sizeof($categoryurl)-2];?>/"><?php echo $prev_post->post_title; ?></a>
<?php endif; ?>
</div>
<div class="next">
<?php
$next_post = get_next_post();
if (!empty( $next_post )): ?>
<a href="<?php echo get_permalink( $next_post->ID ); ?>
<?php echo $categoryurl[sizeof($categoryurl)-2];?>/"><?php echo $next_post->post_title; ?></a>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
Getting the category slug from the URL works well, but I need a way to tell WordPress to use only this category. Maybe working over this part?
$next_post = get_next_post();
Any idea of how to call only a specific category in nex / prev post function?
You can check the website I’m working on here:
https://magoz.is/_beta/follow-your-dreams/?c=personal/
Thank you very much in advance folks!
]]>This is how I am displaying my list of posts:
$args = array("post_type" => "news", 'posts_per_page' => 5, "paged" => $paged, "orderby" => "date", "order" => "DESC");
$wp_query = new WP_Query($args);
My single post pages is single-news.php. It’s not in a loop or anything, it just uses the $post variable to get all of the information for the posts.
I am using get_permalink(get_next_post()->ID)
to get the permalink, however like i stated above it’s not always correct.
I hope that’s enough information for that issue, but alongside this I would also like to be able to detect on the single post page if it’s the last post in the News post type so I can remove the Next Post button.
Thanks!
]]>But now, I want to put another row in between posts, with another <tr>. I do this with something like this:
while (the loop) {
<tr>{thepost}</tr>
<tr>other stuff</tr>
}
But I don’t want the extra row after the last post in the current display. I tried something like this:
while (the loop) {
<tr>{thepost}</tr>
if (!empty(get_next_post())) { <tr> other stuff </tr> }
}
but get_next_post seems to not return empty unless i’m at the very last post (as opposed to the last post per page).
Any ideas how to do this?
]]>