终极Wordpress查询搜索过滤器AJAX结果显示

时间:2018-11-14 21:29:01

标签: ajax wordpress search plugins

我在下面有以下代码。此代码用于显示查询结果。我有2页利用了这一点。

这应适用于页面ID 6196:

get_template_part( 'includes/content', 'profile-loop' );

,并将其更改为页面ID 12537:

get_template_part( 'includes/content', 'highlight-loop' );

我正在寻找一种根据访问者所在页面交换功能的get_template_part部分的方法。

完整功能:

add_filter('uwpqsf_result_tempt', 'customize_output', '', 4);
function customize_output($results , $arg, $id, $getdata ){
 // The Query
        $apiclass = new uwpqsfprocess();
         $query = new WP_Query( $arg );
    ob_start(); $result = '';

    if ( $query->have_posts() ) {
        while ( $query->have_posts() ) {
            $query->the_post();global $post;
                    get_template_part( 'includes/content', 'profile-loop' );
            wp_reset_postdata();
            }
            }
    else {
        echo '<h3 class="center">No results. Try broadening your search parameters.</h3>';
        }

            $results = ob_get_clean();
            return $results;
}

1 个答案:

答案 0 :(得分:0)

您可以使用is_page()函数并按如下所示修改循环:

while ( $query->have_posts() ) {
  $query->the_post();
  global $post;
  if( is_page( 6196 ) ){
  get_template_part( 'includes/content', 'profile-loop' );
}
elseif( is_page( 12537 ) ){
  get_template_part( 'includes/content', 'highlight-loop' );
}
  wp_reset_postdata();
}