maxworkingwell

related posts

Feb 3rd, 2024
1,037
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. function display_related_posts_shortcode($atts) {
  2.  
  3.     // Получаем массив связанных постов
  4.       $related_posts = toolset_get_related_posts(
  5.         199739, // get posts related to this one
  6.         'sector_route', // relationship between the posts
  7.         [
  8.           'query_by_role' => 'parent',
  9.           'role_to_return' => 'child',
  10.           'args' => [
  11.               'meta_key' => 'wpcf-route-position',
  12.           ],
  13.           'orderby' => 'meta_value_num',
  14.           'order' => 'ASC',
  15.           'limit' => -1,
  16.           'return' => 'post_id',
  17.         ],
  18.       );
  19.  
  20.   // Получаем заголовки постов
  21.     $post_titles = array_map('get_the_title', $related_posts);
  22.  
  23.     // Выводим заголовки через запятую
  24.     return implode(', ', $post_titles);
  25. }
  26.  
  27. // Регистрируем шорткод
  28. add_shortcode('display_related_posts', 'display_related_posts_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment