Advertisement
fauzanjeg

Exclude Terms Autoload Next Post

Aug 26th, 2021
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. /* Exclude Terms Autoload Next Post */
  2. function custom_jnews_autoload_post_wrap_attribute($attribute, $post_id) {
  3.     $terms = array('10032', '8070', '1'); /* Terms ID */
  4.    
  5.     $attribute = " data-url=\"" . get_permalink($post_id) . "\" data-title=\"" . esc_attr(get_the_title($post_id)) . "\" data-id=\"" . esc_attr(get_the_ID()) . "\" ";
  6.  
  7.     $content = jnews_get_option('autoload_content', '');
  8.  
  9.     if($content === 'category') {
  10.         $prev_post = get_previous_post(true, null, 'category');
  11.     } else if($content === 'tag') {
  12.         $prev_post = get_previous_post(true, null, 'post_tag');
  13.     } else {
  14.         $prev_post = get_previous_post(null, $terms);
  15.     }
  16.  
  17.     if(!empty($prev_post)) {
  18.         $attribute .= " data-prev=\"" . esc_url(get_permalink($prev_post->ID)) . "\" ";
  19.     }
  20.  
  21.     return $attribute;
  22. }
  23. add_filter('jnews_post_wrap_attribute', 'custom_jnews_autoload_post_wrap_attribute', 99, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement