Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.21 KB | None | 0 0
  1. <?php
  2. /**
  3. * @package WordPress
  4. * @subpackage Kleo
  5. * @author SeventhQueen <themesupport@seventhqueen.com>
  6. * @since Kleo 1.0
  7. */
  8.  
  9. function my_theme_enqueue_styles() {
  10.  
  11. $parent_style = 'kleo-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
  12.  
  13. wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
  14. wp_enqueue_style( 'child-style',
  15. get_stylesheet_directory_uri() . '/style.css',
  16. array( $parent_style ),
  17. wp_get_theme()->get('Version')
  18. );
  19. }
  20. add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
  21.  
  22. /**
  23. * Kleo Child Theme Functions
  24. * Add custom code below
  25. */
  26.  
  27. add_filter( 'wc_product_enable_dimensions_display', '__return_false' );
  28.  
  29. function change_translate_text_multiple( $translated ) {
  30. $text = array(
  31. 'Join Group' => 'Join Fanclub',
  32. 'commented on the post' => 'commented on the article',
  33. 'Leave Group' => 'Leave Fanclub',
  34. 'Search Groups...' => 'Search Fanclubs',
  35. 'Public Group' => 'Public Fanclub',
  36. 'CREATE A GROUP' => 'CREATE A FANCLUB',
  37. 'You joined the group!' => 'You joined the Fanclub!',
  38. 'You successfully left the group.' => 'You succesfully left the Fanclub',
  39. 'Groups' => 'Fanclubs',
  40. 'Your full name' => 'Nickname',
  41. 'Posts' => '',
  42. 'POSTS' => '',
  43. 'Gallery' => 'Media',
  44. 'Create a media' => 'Create an album',
  45. 'Archive for Category:' => '',
  46. 'View Group Results' => 'View Fanclub results',
  47. );
  48. $translated = str_ireplace( array_keys($text), $text, $translated );
  49. return $translated;
  50. }
  51. add_filter( 'gettext', 'change_translate_text_multiple', 20 );
  52.  
  53. add_action( 'widgets_init', 'rkk_widgets_init' );
  54.  
  55. add_post_type_support('forum', array('thumbnail'));
  56. function ks_forum_icons() {
  57. if ( 'forum' == get_post_type() ) {
  58. global $post;
  59. if ( has_post_thumbnail($post->ID) )
  60. echo '<a href="' . get_permalink( $_post->ID ) . '" title="' . get_the_title( $_post->ID ) . '">';
  61. echo get_the_post_thumbnail($post->ID,array(100,100),array('class' => 'alignleft forum-icon'));
  62. echo '</a>';
  63. }
  64. }
  65. add_action('bbp_theme_before_forum_title','ks_forum_icons');
  66.  
  67. function hide_role ($args) {
  68. $args['show_role'] = false ;
  69. Return $args ;
  70. }
  71. add_filter ('bbp_before_get_reply_author_link_parse_args', 'hide_role') ;
  72.  
  73.  
  74. function my_change_profile_tab_order() {
  75. global $bp;
  76. $bp->bp_nav['settings']['position'] = 10;
  77. $bp->bp_nav['activity']['position'] = 20;
  78. $bp->bp_nav['friends']['position'] = 30;
  79. $bp->bp_nav['groups']['position'] = 40;
  80. $bp->bp_nav['articles']['position'] = 20;
  81. $bp->bp_nav['messages']['position'] = 10;
  82. $bp->bp_nav['profile']['position'] = 10;
  83. $bp->bp_nav['bp-messages']['position'] = 10;
  84. $bp->bp_nav['shop']['position'] = 10;
  85. }
  86. add_action( 'bp_setup_nav', 'my_change_profile_tab_order', 999 );
  87.  
  88. function sqr_fix_hover_22082017() {
  89.  
  90. echo '
  91. <style>
  92. .open .kleo-toggle-submenu { display:block !important; }
  93. </style>
  94. ';
  95.  
  96. }
  97.  
  98. add_action('wp_footer', 'sqr_fix_hover_22082017');
  99.  
  100. add_filter('private_title_format', 'ntwb_remove_private_title');
  101. function ntwb_remove_private_title($title) {
  102. return '%s';
  103. }
  104. // class iWC_Orderby_Stock_Status {
  105. // public function __construct() {
  106. // if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
  107. // add_filter('posts_clauses', array($this, 'order_by_stock_status'), 2000);
  108. // }
  109. // }
  110. // public function order_by_stock_status($posts_clauses) {
  111. // global $wpdb;
  112. // if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
  113. // $posts_clauses['join'] .= " INNER JOIN $wpdb->postmeta istockstatus ON ($wpdb->posts.ID = istockstatus.post_id) ";
  114. // $posts_clauses['orderby'] = " istockstatus.meta_value ASC, " . $posts_clauses['orderby'];
  115. // $posts_clauses['where'] = " AND istockstatus.meta_key = '_stock_status' AND istockstatus.meta_value <> '' " . $posts_clauses['where'];
  116. // }
  117. // return $posts_clauses;
  118. // }
  119. // }
  120. // new iWC_Orderby_Stock_Status;
  121. // wp_reset_query();
  122.  
  123.  
  124.  
  125. //Catch ajax requests SuperRadu SQ CUSTOM
  126. add_action( 'wp_ajax_kleo_ajax_search', 'kleo_ajax_search' );
  127. add_action( 'wp_ajax_nopriv_kleo_ajax_search', 'kleo_ajax_search' );
  128.  
  129. if ( ! function_exists( 'kleo_ajax_search' ) ) {
  130. function kleo_ajax_search() {
  131.  
  132. //if "s" input is missing exit
  133. if ( empty( $_REQUEST['s'] ) && empty( $_REQUEST['bbp_search'] ) ) {
  134. die();
  135. }
  136.  
  137. if ( ! empty( $_REQUEST['bbp_search'] ) ) {
  138. $search_string = $_REQUEST['bbp_search'];
  139. } else {
  140. $search_string = $_REQUEST['s'];
  141. }
  142.  
  143. $output = '';
  144. // $context = 'any';
  145. $context = array('post', 'pages', 'groups', 'members', 'forum','product');
  146.  
  147. $defaults = array(
  148. 'numberposts' => 4,
  149. 'posts_per_page' => 20,
  150. 'post_type' => $context,
  151. 'post_status' => array( 'publish', 'inherit' ),
  152. 'post_password' => '',
  153. 'suppress_filters' => false,
  154. 's' => $_REQUEST['s'],
  155. 'category__not_in' => array('1134')
  156. );
  157.  
  158. //Remove woocomerce products since it is handled with a different function
  159. if ( ! empty( $defaults['post_type'] ) && is_array( $defaults['post_type'] ) ) {
  160. foreach ( $defaults['post_type'] as $ptk => $ptv ) {
  161. if ( 'products' == $ptv ) {
  162. unset( $defaults['post_type'][ $ptk ] );
  163. break;
  164. }
  165. }
  166. }
  167.  
  168. //Remove forum since it is handled with a different function
  169. if ( ! empty( $defaults['post_type'] ) && is_array( $defaults['post_type'] ) ) {
  170. foreach ( $defaults['post_type'] as $ptk => $ptv ) {
  171. if ( 'forum' == $ptv ) {
  172. unset( $defaults['post_type'][ $ptk ] );
  173. break;
  174. }
  175. }
  176. }
  177.  
  178. if ( empty( $defaults['post_type'] ) ) {
  179. $posts = null;
  180. } else {
  181.  
  182.  
  183.  
  184. $defaults = apply_filters( 'kleo_ajax_query_args', $defaults );
  185.  
  186. $the_query = new WP_Query( $defaults );
  187. $posts = $the_query->get_posts();
  188. $members = array();
  189. $members['total'] = 0;
  190. $groups = array();
  191. $groups['total'] = 0;
  192. $forums = false;
  193.  
  194. }
  195.  
  196. if ( function_exists( 'bp_is_active' ) && ( $context == "any" || in_array( "members", $context ) ) ) {
  197. $members = bp_core_get_users( array(
  198. 'search_terms' => $search_string,
  199. 'per_page' => $defaults['numberposts'],
  200. 'populate_extras' => false,
  201. ) );
  202. }
  203.  
  204. if ( function_exists( 'bp_is_active' ) && bp_is_active( "groups" ) && ( $context == "any" || in_array( "groups", $context ) ) ) {
  205. $groups = groups_get_groups( array(
  206. 'search_terms' => $search_string,
  207. 'per_page' => $defaults['numberposts'],
  208. 'populate_extras' => false,
  209. ) );
  210. }
  211.  
  212. if ( class_exists( 'bbPress' ) && ( $context == "any" || in_array( "forum", $context ) ) ) {
  213. $forums = kleo_bbp_get_replies( $search_string );
  214. }
  215.  
  216.  
  217. //if there are no posts, groups nor members
  218. if ( empty( $posts ) && $members['total'] == 0 && $groups['total'] == 0 && ! $forums ) {
  219. $output = "<div class='kleo_ajax_entry ajax_not_found'>";
  220. $output .= "<div class='ajax_search_content'>";
  221. $output .= "<i class='icon icon-attention-circled'></i> ";
  222. $output .= esc_html__( "Sorry, we haven't found anything based on your criteria.", 'kleo' );
  223. $output .= "<br>";
  224. $output .= esc_html__( "Please try searching by different terms.", 'kleo' );
  225. $output .= "</div>";
  226. $output .= "</div>";
  227. echo $output; // PHPCS: XSS ok.
  228. die();
  229. }
  230.  
  231. //if there are members
  232. if ( $members['total'] != 0 ) {
  233.  
  234. $output .= '<div class="kleo-ajax-part kleo-ajax-type-members">';
  235. $output .= '<h4><span>' . esc_html__( "Members", 'kleo' ) . '</span></h4>';
  236. foreach ( (array) $members['users'] as $member ) {
  237. $image = '<img src="' . bp_core_fetch_avatar( array(
  238. 'item_id' => $member->ID,
  239. 'width' => 25,
  240. 'height' => 25,
  241. 'html' => false
  242. ) ) . '" class="kleo-rounded" alt="' . esc_attr( $member->display_name ) . '">';
  243. if ( $update = bp_get_user_meta( $member->ID, 'bp_latest_update', true ) ) {
  244. $latest_activity = char_trim( trim( strip_tags( bp_create_excerpt( $update['content'], 50, "..." ) ) ) );
  245. } else {
  246. $latest_activity = '';
  247. }
  248. $output .= "<div class ='kleo_ajax_entry'>";
  249. $output .= "<div class='ajax_search_image'>$image</div>";
  250. $output .= "<div class='ajax_search_content'>";
  251. $output .= "<a href='" . bp_core_get_user_domain( $member->ID ) . "' class='search_title'>";
  252. $output .= esc_html( $member->display_name );
  253. $output .= "</a>";
  254. $output .= "<span class='search_excerpt'>";
  255. $output .= $latest_activity;
  256. $output .= "</span>";
  257. $output .= "</div>";
  258. $output .= "</div>";
  259. }
  260. $output .= "<a class='ajax_view_all' href='" . esc_url( bp_get_members_directory_permalink() . "?s=" . $search_string ) . "'>" . esc_html__( 'View member results', 'kleo' ) . "</a>";
  261. $output .= "</div>";
  262. }
  263.  
  264. //if there are groups
  265. if ( $groups['total'] != 0 ) {
  266.  
  267. $output .= '<div class="kleo-ajax-part kleo-ajax-type-groups">';
  268. $output .= '<h4><span>' . esc_html__( "Groups", 'kleo' ) . '</span></h4>';
  269. foreach ( (array) $groups['groups'] as $group ) {
  270. $image = '<img src="' . bp_core_fetch_avatar( array(
  271. 'item_id' => $group->id,
  272. 'object' => 'group',
  273. 'width' => 25,
  274. 'height' => 25,
  275. 'html' => false
  276. ) ) . '" class="kleo-rounded" alt="' . esc_attr( $group->name ) . '">';
  277. $output .= "<div class ='kleo_ajax_entry'>";
  278. $output .= "<div class='ajax_search_image'>$image</div>";
  279. $output .= "<div class='ajax_search_content'>";
  280. $output .= "<a href='" . bp_get_group_permalink( $group ) . "' class='search_title'>";
  281. $output .= esc_html( $group->name );
  282. $output .= "</a>";
  283. $output .= "</div>";
  284. $output .= "</div>";
  285. }
  286. $output .= "<a class='ajax_view_all' href='" . esc_url( bp_get_groups_directory_permalink() . "?s=" . $search_string ) . "'>" . esc_html__( 'View group results', 'kleo' ) . "</a>";
  287. $output .= "</div>";
  288. }
  289.  
  290. //woocommerce products out of stock at the end SuperRadu SQ CUSTOM
  291. if ( class_exists( 'WooCommerce' ) ) {
  292. $output .= '<div class="kleo-ajax-part kleo-ajax-type-product">';
  293.  
  294. // stuff
  295. $prod_args = array(
  296. 'numberposts' => 4,
  297. 'posts_per_page' => 20,
  298. // 'post_type' => array('product_variation','product'),
  299. 'post_type' => 'product',
  300. 'post_status' => array( 'publish', 'inherit' ),
  301. 'post_password' => '',
  302. 's' => $_REQUEST['s'],
  303. 'meta_key' => '_stock',
  304. // 'meta_key' => '_stock_status',
  305. 'orderby' => 'meta_value_num',
  306. 'order' => 'DESC'
  307.  
  308. );
  309. $prod_query = new WP_Query( $prod_args );
  310. $prod_posts = $prod_query->get_posts();
  311.  
  312. function wc_get_variable_product_stock_quantity( $output = 'raw', $product_id = 0 ){
  313. global $wpdb, $product;
  314.  
  315. // Get the product ID (can be defined)
  316. $product_id = $product_id > 0 ? $product_id : get_the_id();
  317.  
  318. // Check and get the instance of the WC_Product Object
  319. $product = is_a( $product, 'WC_Product' ) ? $product : wc_get_product($product_id);
  320. // Get the stock quantity sum of all product variations (children)
  321. $stock_quantity = $wpdb->get_var("
  322. SELECT SUM(pm.meta_value)
  323. FROM {$wpdb->prefix}posts as p
  324. JOIN {$wpdb->prefix}postmeta as pm ON p.ID = pm.post_id
  325. WHERE p.post_type = 'product_variation'
  326. AND p.post_status = 'publish'
  327. AND p.post_parent = '$product_id'
  328. AND pm.meta_key = '_stock'
  329. AND pm.meta_value IS NOT NULL
  330. ");
  331. return $stock_quantity;
  332. }
  333.  
  334. if ( ! empty( $prod_posts ) ) {
  335. $post_types = array();
  336. $post_type_obj = array();
  337.  
  338. $output .= "<h4><span>PRODUCTS</span></h4>";
  339. $count = 0;
  340. foreach ( $prod_posts as $post ) {
  341. $count ++;
  342. if ( $count > 4 ) {
  343. continue;
  344. }
  345. $format = get_post_format( $post->ID );
  346.  
  347.  
  348. if ( $post->post_type == 'attachment' ) {
  349. $img_url = wp_get_attachment_thumb_url( $post->ID );
  350. $image = '<img src="' . aq_resize( $img_url, 44, 44, true, true, true ) . '" class="kleo-rounded"/>';
  351. } else {
  352. if ( $img_url = kleo_get_post_thumbnail_url( $post->ID ) ) {
  353. $image = aq_resize( $img_url, 44, 44, true, true, true );
  354. if ( ! $image ) {
  355. $image = $img_url;
  356. }
  357. $image = '<img src="' . $image . '" class="kleo-rounded">';
  358. } else {
  359. if ( $format == 'video' ) {
  360. $image = "<i class='icon icon-video'></i>";
  361. } elseif ( $format == 'image' || $format == 'gallery' ) {
  362. $image = "<i class='icon icon-picture'></i>";
  363. } else {
  364. $image = "<i class='icon icon-link'></i>";
  365. }
  366. }
  367. }
  368. $excerpt = "";
  369.  
  370. if ( ! empty( $post->post_content ) ) {
  371. $excerpt = $post->post_content;
  372. $excerpt = preg_replace( "/\[(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", '', $excerpt );
  373. $excerpt = wp_strip_all_tags( $excerpt ); //added to remove gogole adsense code from search excerpt
  374. $excerpt = char_trim( trim( strip_tags( $excerpt ) ), 40, "..." );
  375. }
  376. $link = apply_filters( 'kleo_custom_url', get_permalink( $post->ID ) );
  377. $classes = "format-" . $format;
  378. $output .= "<div class ='kleo_ajax_entry $classes'>";
  379. $output .= "<div class='ajax_search_image'>$image</div>";
  380. $output .= "<div class='ajax_search_content'>";
  381. $output .= "<a href='$link' class='search_title'>";
  382. $output .= get_the_title( $post->ID );
  383. $variation_stock_quantity = wc_get_variable_product_stock_quantity( 'raw', $post->ID );
  384.  
  385. if(get_post_meta( $post->ID, '_stock', true) >= 1 or $variation_stock_quantity >= 1 ) {
  386. $output .= '<span class="instock"> <i class="icon-dot icon-2x"></i> </span>';
  387. }else {
  388. $output .= '<span class="out-of-stock"> <i class="icon-dot icon-2x"></i> </span>';
  389.  
  390. }
  391. $output .= "</a>";
  392. $output .= "<span class='search_excerpt'>";
  393. $output .= $excerpt;
  394. $output .= "</span>";
  395. $output .= "</div>";
  396. $output .= "</div>";
  397. $output .= "</div>";
  398. }
  399.  
  400. }
  401.  
  402. wp_reset_query();
  403. }
  404.  
  405. //if there are posts form certain category SuperRadu SQ CUSTOM
  406. $category = get_category('1134');
  407. $cat_has_posts = $category->category_count;
  408.  
  409. if( $cat_has_posts > 1 ) {
  410. // stuff
  411.  
  412. $args = array(
  413. 's' => $_REQUEST['s'],
  414. 'category__in' => '1134'
  415. //meta_key=keyname
  416. );
  417. $cat_query = new WP_Query( $args );
  418.  
  419. $cat_posts = $cat_query->get_posts();
  420.  
  421. if ( ! empty( $cat_posts ) ) {
  422.  
  423. $output .= '<div class="kleo-ajax-part kleo-ajax-type-news-cat">';
  424. $post_types = array();
  425. $post_type_obj = array();
  426.  
  427. $output .= "<h4><span>NEWS</span></h4>";
  428. $count = 0;
  429. foreach ( $cat_posts as $post ) {
  430. $count ++;
  431. if ( $count > 4 ) {
  432. continue;
  433. }
  434. $format = get_post_format( $post->ID );
  435.  
  436.  
  437. if ( $post->post_type == 'attachment' ) {
  438. $img_url = wp_get_attachment_thumb_url( $post->ID );
  439. $image = '<img src="' . aq_resize( $img_url, 44, 44, true, true, true ) . '" class="kleo-rounded"/>';
  440. } else {
  441. if ( $img_url = kleo_get_post_thumbnail_url( $post->ID ) ) {
  442. $image = aq_resize( $img_url, 44, 44, true, true, true );
  443. if ( ! $image ) {
  444. $image = $img_url;
  445. }
  446. $image = '<img src="' . $image . '" class="kleo-rounded">';
  447. } else {
  448. if ( $format == 'video' ) {
  449. $image = "<i class='icon icon-video'></i>";
  450. } elseif ( $format == 'image' || $format == 'gallery' ) {
  451. $image = "<i class='icon icon-picture'></i>";
  452. } else {
  453. $image = "<i class='icon icon-link'></i>";
  454. }
  455. }
  456. }
  457. $excerpt = "";
  458.  
  459. if ( ! empty( $post->post_content ) ) {
  460. $excerpt = $post->post_content;
  461. $excerpt = preg_replace( "/\[(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", '', $excerpt );
  462. $excerpt = wp_strip_all_tags( $excerpt ); //added to remove gogole adsense code from search excerpt
  463. $excerpt = char_trim( trim( strip_tags( $excerpt ) ), 40, "..." );
  464. }
  465. $link = apply_filters( 'kleo_custom_url', get_permalink( $post->ID ) );
  466. $classes = "format-" . $format;
  467. $output .= "<div class ='kleo_ajax_entry $classes'>";
  468. $output .= "<div class='ajax_search_image'>$image</div>";
  469. $output .= "<div class='ajax_search_content'>";
  470. $output .= "<a href='$link' class='search_title'>";
  471. $output .= get_the_title( $post->ID );
  472. $output .= "</a>";
  473. $output .= "<span class='search_excerpt'>";
  474. $output .= $excerpt;
  475. $output .= "</span>";
  476. $output .= "</div>";
  477. $output .= "</div>";
  478. $output .= "</div>";
  479. }
  480.  
  481. }
  482.  
  483. // wp_reset_query();
  484. }
  485.  
  486.  
  487.  
  488. //if there are posts
  489. if ( ! empty( $posts ) ) {
  490. $post_type_str = array();
  491. $post_types = array();
  492. $post_type_obj = array();
  493.  
  494.  
  495. foreach ( $posts as $post ) {
  496. $post_types[ $post->post_type ][] = $post;
  497. if ( empty( $post_type_obj[ $post->post_type ] ) ) {
  498. $post_type_obj[ $post->post_type ] = get_post_type_object( $post->post_type );
  499. }
  500. }
  501.  
  502. // if(key($post_types) == 'product') {
  503. // echo 'products';
  504. // }else {
  505. // echo 'else ok';
  506. // }
  507.  
  508. if(key($post_types) != 'product' ) {
  509. // if(key($post_types) != 'product' and key($post_types) != 'product_variation') {
  510.  
  511. foreach ( $post_types as $ptype => $post_type ) {
  512.  
  513. $output .= '<div class="kleo-ajax-part kleo-ajax-type-' . esc_attr( $post_type_obj[ $ptype ]->name ) . '">';
  514. if ( isset( $post_type_obj[ $ptype ]->labels->name ) ) {
  515. $output .= "<h4><span>" . $post_type_obj[ $ptype ]->labels->name . "</span></h4>";
  516. } else {
  517. $output .= "<hr>";
  518. }
  519. $count = 0;
  520.  
  521. foreach ( $post_type as $post ) {
  522.  
  523. $post_type_str[ $post->post_type ] = $post->post_type;
  524. $count ++;
  525. if ( $count > 4 ) {
  526. continue;
  527. }
  528. $format = get_post_format( $post->ID );
  529.  
  530. if ( $post->post_type == 'attachment' ) {
  531. $img_url = wp_get_attachment_thumb_url( $post->ID );
  532. $image = '<img src="' . aq_resize( $img_url, 44, 44, true, true, true ) . '" class="kleo-rounded"/>';
  533. } else {
  534. if ( $img_url = kleo_get_post_thumbnail_url( $post->ID ) ) {
  535. $image = aq_resize( $img_url, 44, 44, true, true, true );
  536. if ( ! $image ) {
  537. $image = $img_url;
  538. }
  539. $image = '<img src="' . $image . '" class="kleo-rounded">';
  540. } else {
  541. if ( $format == 'video' ) {
  542. $image = "<i class='icon icon-video'></i>";
  543. } elseif ( $format == 'image' || $format == 'gallery' ) {
  544. $image = "<i class='icon icon-picture'></i>";
  545. } else {
  546. $image = "<i class='icon icon-link'></i>";
  547. }
  548. }
  549. }
  550. $excerpt = "";
  551.  
  552. if ( ! empty( $post->post_content ) ) {
  553. $excerpt = $post->post_content;
  554. $excerpt = preg_replace( "/\[(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", '', $excerpt );
  555. $excerpt = wp_strip_all_tags( $excerpt ); //added to remove gogole adsense code from search excerpt
  556. $excerpt = char_trim( trim( strip_tags( $excerpt ) ), 40, "..." );
  557. }
  558. $link = apply_filters( 'kleo_custom_url', get_permalink( $post->ID ) );
  559. $classes = "format-" . $format;
  560. $output .= "<div class ='kleo_ajax_entry $classes'>";
  561. $output .= "<div class='ajax_search_image'>$image</div>";
  562. $output .= "<div class='ajax_search_content'>";
  563. $output .= "<a href='$link' class='search_title'>";
  564. $output .= get_the_title( $post->ID );
  565. $output .= "</a>";
  566. $output .= "<span class='search_excerpt'>";
  567. $output .= $excerpt;
  568. $output .= "</span>";
  569. $output .= "</div>";
  570. $output .= "</div>";
  571.  
  572. $output .= '</div>';
  573. }
  574. }
  575. wp_reset_query();
  576. }
  577. if ( ! empty( $post_type_str ) ) {
  578. if ( count( $post_type_str ) > 1 ) {
  579. $search_str_posts = '&post_type[]=' . implode( '&post_type[]=', $post_type_str );
  580. } else {
  581. $search_str_posts = '&post_type=' . implode( ',', $post_type_str );
  582. }
  583.  
  584. } else {
  585. $search_str_posts = '';
  586. }
  587.  
  588. $output .= "<a class='ajax_view_all' href='" . esc_url( home_url( '/' ) . '?s=' . $search_string ) . $search_str_posts . "'>" . esc_html__( 'View all results', 'kleo' ) . "</a>";
  589.  
  590. // wp_reset_query();
  591.  
  592.  
  593. }
  594.  
  595. /* Forums topics search */
  596. if ( ! empty( $forums ) ) {
  597. $output .= '<div class="kleo-ajax-part kleo-ajax-type-forums">';
  598. $output .= '<h4><span>' . esc_html__( "Forums", 'kleo' ) . '</span></h4>';
  599.  
  600. $i = 0;
  601. foreach ( $forums as $fk => $forum ) {
  602.  
  603. $i ++;
  604. if ( $i <= 4 ) {
  605. $image = "<i class='icon icon-chat-1'></i>";
  606.  
  607. $output .= "<div class ='kleo_ajax_entry'>";
  608. $output .= "<div class='ajax_search_image'>$image</div>";
  609. $output .= "<div class='ajax_search_content'>";
  610. $output .= "<a href='" . esc_url( $forum['url'] ) . "' class='search_title'>";
  611. $output .= wp_kses_post( $forum['name'] );
  612. $output .= "</a>";
  613. //$output .= "<span class='search_excerpt'>";
  614. //$output .= $latest_activity;
  615. //$output .= "</span>";
  616. $output .= "</div>";
  617. $output .= "</div>";
  618. }
  619. }
  620. $output .= "<a class='ajax_view_all' href='" . esc_url( bbp_get_search_url() . "?bbp_search=" . $search_string ) . "'>" .
  621. esc_html__( 'View forum results', 'kleo' ) .
  622. "</a>";
  623. $output .= "</div>";
  624. }
  625.  
  626.  
  627. echo $output; // PHPCS: XSS ok.
  628. die();
  629. }
  630. }
  631.  
  632.  
  633.  
  634. //add_action( 'pre_get_posts', function ( $q ) {
  635. // if ( !is_admin() // Target only front end
  636. // && $q->is_main_query() // Only target the main query
  637. // && $q->is_search() // Change to suite your needs
  638. // ) {
  639. // $q->set( 'meta_key', '_stock_status' );
  640. // $q->set( 'orderby', 'meta_value' );
  641. // $q->set( 'order', 'ASC' );
  642. // }
  643. // }, PHP_INT_MAX );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement