How can I get next post id after current post id for custom post type

If you are using the code inside a custom post type template, then the get_next_post() will get the next post for you. Then you can use the ->ID and get it’s ID. So: $next_post = get_next_post(); $next_post_id = $next_post->ID; If you need their link, simply use next_post_link() or previous_post_link(). These functions use the global post … Read more

How can I limit the length of the previous/next posts in my WordPress Theme?

Here’s a little coding that should implement this for you: <?php $max_length = 5; // set max character length here $next = get_next_post()->ID; $prev = get_previous_post()->ID; if( $prev ) { $title = get_the_title( $prev ); $link = get_the_permalink( $prev ); $post_name = mb_strlen( $title ) > $max_length ? mb_substr( $title, 0, $max_length ) . ‘ … Read more

next and previous post link ordered alphabetically

Find the solution: The hole snippet looks like this: <?php function filter_next_post_sort($sort) { global $post; if (get_post_type($post) == ‘MyCustomPostType’) { $sort = “ORDER BY p.post_title ASC LIMIT 1”; } else{ $sort = “ORDER BY p.post_date ASC LIMIT 1”; } return $sort; } function filter_next_post_where($where) { global $post, $wpdb; if (get_post_type($post) == ‘MyCustomPostType’) { return $wpdb->prepare(“WHERE … Read more

How can I get next/ previous post links to order by a filter (by the last word of the title)?

Reviewing the MySQL string functions, it looks like you could use the SUBSTRING_INDEX() function: ORDER BY SUBSTRING_INDEX( p.post_title, ‘ ‘, -1 ) {ASC|DESC} LIMIT 1 to order by the last word of the post title. You could test this method within your orderby filters. Example: Prev/Next CPT – ordered by last word in post title … Read more

Prev/Next child navigation for current page?

All right, here it is, fully working: <?php $pagelist = get_pages(“child_of=”.$post->post_parent.”&parent=”.$post->post_parent.”&sort_column=menu_order&sort_order=asc”); $pages = array(); foreach ($pagelist as $page) { $pages[] += $page->ID; } $current = array_search($post->ID, $pages); $prevID = $pages[$current-1]; $nextID = $pages[$current+1]; ?> <div class=”navigation”> <?php if (!empty($prevID)) { ?> <div class=”previous”> <a href=”https://wordpress.stackexchange.com/questions/54422/<?php echo get_permalink($prevID); ?>” title=”<?php echo get_the_title($prevID); ?>”>Previous</a> </div> <?php } … Read more

Filter get_adjacent_post() for private posts, how to modify JOIN/WHERE?

First of all I suggest you to use a function to return the terms to exclude, that will help you to get them in different places without having to repeat code, e.g. in the ‘pre_get_posts’ filter and the adjacent post filters. So: function get_level_term_to_exclude() { if ( current_user_can (‘manage_options’) || current_user_can (‘view_level1_posts’) ) { return … Read more

techhipbettruvabetnorabahisbahis forumutaraftarium24eduedusedueduseduseduseduedueduedus