2016-07-22 30 views
5

Iwannフィルターリンクを追加 enter image description hereカスタムポストタイプのカスタムメタボックスのWordPressにフィルタを追加するには?

ありがとうございます。

+0

あなたは、このリンクを参照してくださいもらえますか? http://wordpress.stackexchange.com/questions/45436/add-filter-menu-to-admin-list-of-posts-of-custom-type-to-filter-posts-by-custo – purvik7373

+0

明確にするあなたの店の名前は何ですか? –

+0

私のストア名のように。 1)hearten cafe 2)クイックトラック40 3)クイックトラック51 同様に –

答えて

1

チェックこの

add_action('restrict_manage_posts', 'our_drink_filter'); 
/** 
* First create the dropdown 
* make sure to change POST_TYPE to the name of your custom post type 
* 
* @author Ohad Raz 
* 
* @return void 
*/ 
function our_drink_filter(){ 
    $type = 'post'; 
    if (isset($_GET['post_type'])) { 
     $type = $_GET['post_type']; 
    } 

    //only add filter to post type you want 
    if ('our_drink' == $type){ 
     //change this to the list of values you want to show 
     //in 'label' => 'value' format 
     $filter_post = array(); 
     $all_movies1 = get_posts(array(
      'post_type' => 'our_restaurant', 
      'numberposts' => -1, 
      'orderby' => 'post_title', 
      'order' => 'ASC' 
      )); 
      foreach ($all_movies1 as $movie1) : 
       //echo $movie1->post_title." ".sanitize_title($movie1->post_title)."<br>"; 
       array_push($filter_post[$movie1->post_title] = sanitize_title($movie1->post_title)); 

      endforeach; 
     ?> 
     <select name="ADMIN_FILTER_FIELD_VALUE"> 
     <option value=""><?php _e('Store Name ', 'wose45436'); ?></option> 
     <?php 
      $current_v = isset($_GET['ADMIN_FILTER_FIELD_VALUE'])? $_GET['ADMIN_FILTER_FIELD_VALUE']:''; 
      foreach ($filter_post as $label => $value) { 
       printf 
        (
         '<option value="%s"%s>%s</option>', 
         $value, 
         $value == $current_v? ' selected="selected"':'', 
         $label 
        ); 
       } 
     ?> 
     </select> 
     <?php 
    } 
} 


add_filter('parse_query', 'drink_posts_filter'); 
/** 
* if submitted filter by post meta 
* 
* make sure to change META_KEY to the actual meta key 
* and POST_TYPE to the name of your custom post type 
* @author Ohad Raz 
* @param (wp_query object) $query 
* 
* @return Void 
*/ 
function drink_posts_filter($query){ 
    global $pagenow; 
    $type = 'post'; 
    if (isset($_GET['post_type'])) { 
     $type = $_GET['post_type']; 
    } 
    if ('our_drink' == $type && is_admin() && $pagenow=='edit.php' && isset($_GET['ADMIN_FILTER_FIELD_VALUE']) && $_GET['ADMIN_FILTER_FIELD_VALUE'] != '') { 
     $query->query_vars['meta_key'] = 'custom_element_grid_class_meta_box'; 
     $query->query_vars['meta_value'] = $_GET['ADMIN_FILTER_FIELD_VALUE']; 
    } 
} 
+0

これは私が探しているものですbirendraありがとうございます。 –

-1

これはプラグインのようです。これを行うには、そのプラグインのコードを変更する必要があります。そのプラグインの内容を知らなくても、私はあなたに伝えることができませんでした。プラグインのアップデートがロードされていれば、そのオプトンを表示しても問題は残ります。だからあなたの最善の策は、プラグインの作者にリクエストすることです。

+0

私はプラグインを使用していません。これは、ストア名がカスタムメタフィールドである私のカスタムポストタイプです。私はそれを管理パネルに表示するように管理します。今私のクライアントはフィルタとしてそれを必要とします。 –

+0

私がこれで見た最高のものはここですhttps://www.smashingmagazine.com/2013/12/modifying-admin-post-lists-in-wordpress/ – Danimal

関連する問題