Advertisement
sierre

Link To Latest Post Shortcode - Using Avada Builder Button module

Apr 24th, 2022
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. // ticket #18623
  2. // for page https://thecollegemap.com/your-path/
  3. // Link To Latest Post Shortcode - Using Avada Builder Button module
  4.  
  5. // Link to latest post shortcode
  6. // USAGE: [linkto_latest_post]
  7. function linkto_latest_post_shortcode($atts, $content = null) {
  8.    
  9.     global $post;
  10.    
  11.     $args = array(
  12.         'category_name'  => 'your-path',
  13.         'posts_per_page' => '1',
  14.         'order'          => DESC,
  15.         'orderby'        => 'post_date',
  16.     );
  17.    
  18.     $output = '';
  19.    
  20.     $posts = get_posts($args);
  21.    
  22.     foreach($posts as $post) {
  23.        
  24.         setup_postdata($post);
  25.        
  26.         $output .= get_the_permalink();
  27.        
  28.     }
  29.    
  30.     wp_reset_postdata();
  31.    
  32.     return $output;
  33.    
  34. }
  35. add_shortcode('linkto_latest_post', 'linkto_latest_post_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement