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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)