天道酬勤,学无止境

custom-post-type

WordPress 自定义帖子类型未显示在搜索结果中(WordPress Custom Post Type not showing in Search Results)

问题 我对 WordPress 中的自定义帖子类型(测验)和搜索有疑问。 自定义帖子类型未显示在我的搜索结果页面中。 我的搜索结果中仅显示默认帖子内容。 以下是我使用的代码 函数.php 函数 create_posttype() { register_post_type( 'compassquiz', array( 'labels' => array( 'name' => __( 'Compass Quiz' ), 'singular_name' => __( 'Compass Quiz' ) ), 'taxonomies' => array('post_tag'), 'public' => true, 'publicly_queryable' => true, 'has_archive' => true, 'rewrite' => array('slug' => 'free-quiz-bank-exam'), 'query_var' => true, 'exclude_from_search' => false, ) );} add_action( 'init', 'create_posttype' ); functions.php 中的附加代码 //Read Custom Post types in Search function filter_search($query) {

2022-01-16 13:07:50    分类:技术分享    php   wordpress   search   custom-post-type

自定义帖子类型和自定义重写规则的 Wordpress 分页问题(Wordpress pagination issues with Custom Post Type and custom rewrite rule)

问题 我们使用最新的 WP (5.2.2)。 我们有一个名为 Stories (slug: stories ) 的自定义帖子类型,在设置过程中具有以下功能。 Public: true Publicly Queryable: true Show UI: true Has Archive: true Exclude From Search: false Hierarchical: false Rewrite: true Custom Rewrite Slug: stories/%category% Show in Nav Menus: true Show in REST API: true With Front: true Query Var: true 这工作正常。 例如,我们创建一个名为“Huckleberry Cafe Opens”的新故事,并将其分配给一个名为“食物”的类别,并且 URL 有效: site.com/stories/food/huckleberry-cafe-open 我们的永久链接设置为/%category%/%postname% ,但对于自定义帖子类型,我们还使用有用的插件Permalink Manager Lite 。 这包含“permastructures”,我们使用与上面自定义帖子类型中的“自定义重写 slug”匹配的模式: stories/

2022-01-16 05:32:42    分类:技术分享    wordpress   pagination   custom-post-type

WordPress Custom Post Type not showing in Search Results

I have an issue with custom post types(Quiz) & search in WordPress. Custom post types are not showing in my search result page. Only the default post content is showing in my search result. Following are the codes I used functions.php function create_posttype() { register_post_type( 'compassquiz', array( 'labels' => array( 'name' => __( 'Compass Quiz' ), 'singular_name' => __( 'Compass Quiz' ) ), 'taxonomies' => array('post_tag'), 'public' => true, 'publicly_queryable' => true, 'has_archive' => true, 'rewrite' => array('slug' => 'free-quiz-bank-exam'), 'query_var' => true, 'exclude_from_search

2022-01-16 04:34:54    分类:问答    php   wordpress   search   custom-post-type

具有自定义帖子类型的木材分页(Timber pagination with custom post type)

问题 我正在尝试使用 Timber docs 中显示的示例进行自定义帖子类型的分页。 这不像我预期的那样工作。 我获得分页输出的唯一方法是添加query_posts($args); 在我设置了我的查询$args ,在我将它们传递到一个新的Timber\PostQuery但是从我读过的所有内容Timber\PostQuery ,我不应该这样做。 我已经阅读了这个问题线程,但它似乎依赖于直接使用WP_Query ,我试图让这个任务尽可能简单。 任何提示将不胜感激。 回答1 好吧,我看不到这是在哪里记录的,但是这种结构似乎对我pagination()在我的 CPT 集合上调用pagination() ): $args = array( 'post_type' => 'my_custom_post_type', 'posts_per_page' => 5, 'paged' => $paged ); $myCollection = new Timber\PostQuery($args); $context['collection'] = $myCollection; $context['pagination'] = $myCollection->pagination(); 然后我必须设置 Routes::map 才能使分页实际工作。 这是一个例子: function add_routes()

2022-01-15 19:21:55    分类:技术分享    pagination   custom-post-type   timber

在自定义列中显示高级自定义字段值 (wp_list_table)(Show advanced custom field value in custom column (wp_list_table))

问题 我创建了一个名为address的自定义帖子类型,并使用插件高级自定义字段为其添加了值。 我想在 wp-list-table 的自定义列中显示这些值。 所以我设法在名为views的自定义帖子类型(地址)中添加了一列。 使用下面的代码。 add_filter('manage_edit-address_columns', 'my_columns'); function my_columns($columns) { $columns['views'] = 'Views'; return $columns; } 现在我想用我制作并称为“reserveer_url_theater_terra” (它是一个 url 字段)并绑定到自定义帖子类型地址的高级自定义字段中的数据填充此列(视图),但它只显示一个空列“视图” ' 没有来自'reserveer_url_theater_terra'字段的值。 我做错了什么,有人能指出我正确的方向吗? 我应该使用 wpdb 来获取值吗? 或者还有什么我应该做的吗? 先感谢您。 add_action('manage_posts_custom_column', 'my_show_columns'); function my_show_columns($name) { global $post; switch ($name) { case 'views':

2022-01-14 12:55:07    分类:技术分享    wordpress   function   custom-post-type   advanced-custom-fields

Show advanced custom field value in custom column (wp_list_table)

I made a custom post type named address and added values to it with the plugin advanced custom fields. I would like to display those values in a custom column in the wp-list-table. So I managed to add a column to the custom post type(address) called views. With the code below. add_filter('manage_edit-address_columns', 'my_columns'); function my_columns($columns) { $columns['views'] = 'Views'; return $columns; } Now I wanted to fill this column (views) with the data from the advanced custom field wich I made and called 'reserveer_url_theater_terra' (it's a url field) and bound to the custom

2022-01-14 08:10:31    分类:问答    wordpress   function   custom-post-type   advanced-custom-fields

wp作业管理器自定义过滤器日期(wp job manager custom filter on date)

问题 我正在使用“wp 作业管理器”并尝试按开始日期过滤/搜索。 这对我不起作用这是我的代码。 add_filter('job_manager_get_listings','filter_by_date_field_query_args', 10, 2); function filter_by_date_field_query_args($query_args, $args) { if (isset($_POST['form_data'])) { parse_str($_POST['form_data'], $form_data); // If this is set, we are filtering by salary if (!empty($form_data['start_date'])) { $date = sanitize_text_field($form_data['start_date']); $start_date = date('Y-m-d',strtotime($date." +15 days")); $end_date = date('Y-m-d',strtotime($date." -15 days")); $query_args['meta_query'][] = array( 'key' => 'date', 'value' => array(

2022-01-14 07:15:15    分类:技术分享    php   wordpress   custom-post-type

Wordpress pagination issues with Custom Post Type and custom rewrite rule

We use latest WP (5.2.2). We have a custom post type called Stories (slug: stories) with the following capabilities during setup. Public: true Publicly Queryable: true Show UI: true Has Archive: true Exclude From Search: false Hierarchical: false Rewrite: true Custom Rewrite Slug: stories/%category% Show in Nav Menus: true Show in REST API: true With Front: true Query Var: true This works fine. For example, we create a new story called "Huckleberry Cafe Opens" and assign it to a category called "Food", and the URL works: site.com/stories/food/huckleberry-cafe-open Our permalinks are set to /

2022-01-14 00:37:17    分类:问答    wordpress   pagination   custom-post-type

Timber pagination with custom post type

I am trying to use the example shown in the Timber docs for pagination with a custom post type. This is not working as I'd expect. The only way I've gotten a pagination to output is to add query_posts($args); after I set up my query $args and before I pass them into a new Timber\PostQuery but from everything I've read, I shouldn't be doing this. I have read this issue thread, but it seems to rely on using WP_Query directly, and I'm trying to keep this task as simple as possible. Any tips would be appreciated.

2022-01-13 03:14:58    分类:问答    pagination   custom-post-type   timber

在 Wordpress 中为自定义帖子类型创建分页(Create pagination for custom post types in Wordpress)

问题 我有一个要添加分页的活动页面。 但是,由于它是自定义帖子类型,我发现它相当困难。 我已经设法为我的新闻页面进行分页,但我无法为事件页面获得相同的结果。 这是我的活动页面代码 <?php get_header(); get_sidebar('left'); ?> <article class="content-main events" role="main" id="post-<?php the_ID() ?>"> <?php include 'breadcrumbs.php'; ?> <?php query_posts(array('posts_per_page'=>'2')); ?> <?php while (have_posts()) : the_post(); ?> <div class="news-post"> <h1><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h1> <?php the_excerpt() ?> </div> <?php endwhile; ?> <?php wp_reset_query(); ?> <!--Pagination--> <?php echo paginate_links( $args ) ?> <?php global $wp_query; $big =

2022-01-12 09:33:23    分类:技术分享    wordpress   pagination   custom-post-type