【问题标题】:Wordpress: Search items in tableWordpress:在表格中搜索项目
【发布时间】:2015-07-03 10:59:45
【问题描述】:

我创建了一个测试页面,用户可以在其中访问 pdf 和 word 文档。

网站:http://recordandreturn2.insctest1.com/online-forms

wordpress 网站的默认搜索功能不会在您输入任何项目后显示它们。例如,搜索“Affidavit of Heirship”。我正在使用一个名为 easy table 的插件,因为客户端需要轻松添加或删除向前移动的项目。我搜索了 wordpress 搜索功能增强器,但似乎没有任何效果。

这个示例网站有一个搜索功能,可以显示表单,这就是我想要实现的:http://www.judicialtitle.com/resources/forms

【问题讨论】:

标签: php html css wordpress plugins


【解决方案1】:

这是一个能够搜索简码的插件: https://wordpress.org/plugins/wp-ultimate-search/

或者,您可以将以下内容添加到 functions.php 以在搜索中包含短代码

<?php
//Replace wp_trim_excerpt with a commented out strip_shortcodes()
function improved_trim_excerpt($text) {
    $raw_excerpt = $text;
    if ( '' == $text ) {
        $text = get_the_content('');

        //$text = strip_shortcodes( $text );

        $text = apply_filters('the_content', $text);
        $text = str_replace(']]>', ']]>', $text);
        $text = strip_tags($text);
        $excerpt_length = apply_filters('excerpt_length', 55);
        $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
        $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
        if ( count($words) > $excerpt_length ) {
            array_pop($words);
            $text = implode(' ', $words);
            $text = $text . $excerpt_more;
        } else {
            $text = implode(' ', $words);
        }
    }
    return apply_filters('improved_trim_excerpt', $text, $raw_excerpt);
}

remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'improved_trim_excerpt');

//You might also need to add this in order to make sure the 
//shortcodes are actually parsed and not just displayed
//$text = do_shortcode($text);
?>

此代码来自http://3rdplanetwebsolutions.com/news/add-shortcode-content-to-wordpress-search-results/

【讨论】:

  • 太棒了,我会试试这个。我对此还是很陌生。它说要替换 wp_trim_excerpt ,我将在 Easy Table wordpress 插件的短代码中插入? wordpress.org/plugins/easy-table
  • 不,这只是解释代码的作用。您无需编辑任何内容。
猜你喜欢
  • 2012-03-30
  • 1970-01-01
  • 2014-12-20
  • 2014-04-21
  • 2015-08-31
  • 1970-01-01
  • 2023-02-01
  • 2015-04-09
  • 2018-10-01
相关资源
最近更新 更多