停止显示自定义帖子类型的wordpress搜索(stop wordpress search showing a custom post type)

编程入门 行业动态 更新时间:2024-10-24 14:24:27
停止显示自定义帖子类型的wordpress搜索(stop wordpress search showing a custom post type)

我有一个自定义帖子类型,用于使用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; } }

更多推荐

本文发布于:2023-07-24 20:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1250535.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   类型   帖子   wordpress   stop

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!