2015-10-06 93 views
0

我有一個像下面的自定義帖子類型(尚未定製)。從WordPress的自定義帖子類型獲得標題

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的用戶輸入進行比較,然後顯示最相關的帖子。

+0

你想獲得這個自定義後類型的所有帖子標題獲取Post title? –

+2

[get_posts](https://codex.wordpress.org/Function_Reference/get_posts)和[the_title](https://codex.wordpress.org/Function_Reference/the_title)? – vard

+0

如果你有帖子ID,'get_the_title($ ID);'應該訣竅 –

回答

1

在我的插件自定義後類型註冊

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'); 

php

<?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; 
    } ?> 
+0

它的工作原理。謝謝! – mattesj

相關問題