我有一个自定义帖子类型,用于使用uncode主题构建的页面上的某些文本块。 我需要将这些块公开,以便它们显示在页面上,但我想阻止它们出现在搜索结果中。
search.php不像普通的wordpress搜索文件,它是uncode-theme文件,并没有正常的查询,我不这么认为,所以我想我需要一个函数呢?
任何人都可以建议如何实现这一目标?
CPT是'静态内容'
谢谢!
I have one custom post type I use for some text blocks on a page built using uncode theme. I need these blocks to be public so they display on the page but I want to stop them appearing in search results.
The search.php isn't like a normal wordpress search file, it is the uncode-theme file and doesn't have normal queries in I don't think so I'm thinking I need a function maybe?
Can anyone please advise how to achieve this?
The CPT is 'staticcontent'
Thanks!
最满意答案
这里的答案取决于您是通过自己的代码创建CPT,还是其他插件正在创建CPT。 请参阅此链接以获取对这两种方法的完美说明:
http://www.webtipblog.com/exclude-custom-post-type-search-wordpress/
基本要点是:
如果您正在创建自己的CPT,可以在register_post_type()调用'exclude_from_search' => true添加一个参数
如果另一个插件/主题正在创建CPT,您需要稍后设置此exclude_from_search变量,作为CPT过滤器的一部分,如下所示:
// functions.php add_action( 'init', 'update_my_custom_type', 99 ); function update_my_custom_type() { global $wp_post_types; if ( post_type_exists( 'staticcontent' ) ) { // exclude from search results $wp_post_types['staticcontent']->exclude_from_search = true; } }The answer here depends on whether you're creating the CPT via your own code, or if another plugin is creating the CPT. See this link for a great explanation of both approaches:
http://www.webtipblog.com/exclude-custom-post-type-search-wordpress/
The basic gist is this:
If you're creating your own CPT, you can add an argument to the register_post_type() call of 'exclude_from_search' => true
If another plugin / theme is creating the CPT, you need to set this exclude_from_search variable later on, as part of a filter to the CPT, as such:
// functions.php add_action( 'init', 'update_my_custom_type', 99 ); function update_my_custom_type() { global $wp_post_types; if ( post_type_exists( 'staticcontent' ) ) { // exclude from search results $wp_post_types['staticcontent']->exclude_from_search = true; } }更多推荐
发布评论