从Wordpress自定义帖子类型获取标题

Mattesj

我有一个如下的自定义帖子类型(尚未自定义)。

function movie_reviews_init() {

    $args = array(
      'label' => 'Movie Reviews',
        'public' => true,
        'show_ui' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'rewrite' => array('slug' => 'movie-reviews'),
        'query_var' => true,
        'menu_icon' => 'dashicons-video-alt',
        'show_in_menu' => 'myplugin',
        'supports' => array(
            'title',
            'editor',
            'page-attributes',)
        );
    register_post_type( 'movie-reviews', $args );
}

我看了又看,但是想不出如何从帖子中获得标题。我需要在变量中添加标题,以便与使用levenshtein-distance的用户输入进行比较,然后显示最相关的帖子。

巴韦什瓦拉

在我的插件自定义帖子中,输入注册

function register_cpt_gallery() {
        $labels = array(
            'name' => _x( 'Gallery', 'gallery' ),
            'singular_name' => _x( 'gallery', 'gallery' ),
            'add_new' => _x( 'Add New Album', 'gallery' ),
            'add_new_item' => _x( 'Add New Album', 'gallery' ),
            'edit_item' => _x( 'Edit gallery', 'gallery' ),
            'new_item' => _x( 'New Album', 'gallery' ),
            'view_item' => _x( 'View Album', 'gallery' ),
            'search_items' => _x( 'Search Album', 'gallery' ),
            'not_found' => _x( 'No Album found', 'gallery' ),
            'not_found_in_trash' => _x( 'No Album found in Trash', 'gallery' ),
            'parent_item_colon' => _x( 'Parent Album:', 'gallery' ),
            'menu_name' => _x( 'Gallery', 'gallery' ),
        ); 
        $args = array(
            'labels' => $labels,
            'hierarchical' => true,
            'description' => 'Gallery filterable by genre',
            'supports' => array( 'title', 'editor', '', 'thumbnail', '', '', '', '', '' ),
            'taxonomies' => array( 'genres' ),
            'public' => true,
            'show_ui' => true,
            'show_in_menu' => true,
            'menu_position' => 5,
            'menu_icon' => 'dashicons-images-alt',
            'show_in_nav_menus' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => false,
            'has_archive' => true,
            'query_var' => true,
            'can_export' => true,
            'rewrite' => true,
            'capability_type' => 'post'
        ); 
        register_post_type( 'gallery', $args );
    }
    add_action( 'init', 'register_cpt_gallery' );

获取Post titlephp页面

<?php $gallery_args = array(
                'posts_per_page'   => -1,
                'orderby'=> 'date',
                'order'=> 'DESC',
                'post_type'=> 'gallery',
                'post_status'=> 'publish',
                'suppress_filters' => true 
        );
    $posts_display_gallery = get_posts( $gallery_args ); 
    foreach($posts_display_gallery as $rows){
        $post_title = $rows->post_title;
    } ?>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

排序和显示自定义帖子类型Wordpress

wordpress获取wordpress循环中自定义帖子类型的类别名称?

WordPress自定义帖子类型列排序查询

从Wordpress取消注册自定义帖子类型

停止显示自定义帖子类型的wordpress搜索

WordPress木材获取自定义帖子类型的帖子

Wordpress自定义帖子类型分类模板

在Wordpress中创建隐藏的自定义帖子类型

简码内的Wordpress自定义帖子类型循环

WordPress的自定义帖子类型变量重叠?

Wordpress插件自定义帖子类型单页

限制Gutenberg Editor的自定义帖子类型wordpress

如何获取自定义帖子类型的标题作为其相关帖子的链接?

WordPress:自定义帖子类型导致404页

显示自定义帖子类型存档的类别和帖子标题-Wordpress

WordPress的自定义帖子类型帖子不显示

在Wordpress中显示自定义帖子类型的内容

如何在Wordpress中获取自定义帖子类型的最新帖子ID

WordPress自定义帖子类型

自定义帖子类型Wordpress按类别查询

自定义帖子类型中的Wordpress列表类别

WordPress按类别获取自定义帖子类型的帖子

Wordpress遍历自定义帖子类型并打印出帖子标题

使Wordpress中的自定义帖子类型不可搜索

Wordpress 自定义帖子类型当前帖子

从自定义帖子类型 Wordpress 的类别中获取帖子

显示自定义帖子类型类别 (Wordpress)

在 wordpress 自定义帖子类型查询中获取当前帖子类别 slug

强制 Wordpress 仅在特定的自定义帖子类型上从标题生成帖子 slug