【问题标题】:Add Custom ComboBox Filters to Admin User List in Wordpress将自定义组合框过滤器添加到 Wordpress 中的管理员用户列表
【发布时间】:2011-11-26 19:52:37
【问题描述】:

我想在管理员用户列表面板中添加 2 个组合框。例如,第一个是包含国家/地区的组合框,另一个组合是用户年龄。 所以我想添加这些组合来过滤用户列表。

你能在这里说明一下吗?

谢谢。

【问题讨论】:

    标签: wordpress list filter


    【解决方案1】:

    这就是我要找的:

    add_action('restrict_manage_posts', 'my_restrict_manage_posts');
    function my_restrict_manage_posts()
    {
      global $typenow;
    
      if ($typenow == 'your_custom_post_type') {
        $args = array(
          'show_option_all' => "Show All Categories",
          'taxonomy' => 'your_custom_taxonomy',
          'name' => 'your_custom_taxonomy'
    
        );
        wp_dropdown_categories($args);
      }
    }
    
    add_action('request', 'my_request');    
    function my_request($request)
    {
      if (is_admin() && $GLOBALS['PHP_SELF'] == '/wp-admin/edit.php' && isset($request['post_type']) && $request['post_type'] == 'your_custom_post_type') {
        $request['term'] = get_term($request['your_custom_taxonomy'], 'your_custom_taxonomy')->name;
      }
      return $request;
    }
    

    【讨论】:

      【解决方案2】:

      您可以将自己的字段添加到用户添加/编辑字段。
      这个例子展示了如何添加地址输入字段,如果你得到这个工作尝试用你需要的下拉菜单切换它。如果这就是“组合框”的意思

      function fb_add_custom_user_profile_fields( $user ) {
      ?>
          <h3><?php _e('Extra Profile Information', 'your_textdomain'); ?></h3>
          <table class="form-table">
          <tr>
          <th>
          <label for="address"><?php _e('Address', 'your_textdomain'); ?>
          </label></th>
          <td>
          <input type="text" name="address" id="address" value="<?php echo esc_attr( get_the_author_meta( 'address', $user->ID ) ); ?>" class="regular-text" /><br />
          <span class="description"><?php _e('Please enter your address.', 'your_textdomain'); ?></span>
          </td>
          </tr>
          </table>
          <?php }
          function fb_save_custom_user_profile_fields( $user_id ) {
          if ( !current_user_can( 'edit_user', $user_id ) )
          return FALSE;
          update_usermeta( $user_id, 'address', $_POST['address'] );
          }
          add_action( 'show_user_profile', 'fb_add_custom_user_profile_fields' );
          add_action( 'edit_user_profile', 'fb_add_custom_user_profile_fields' );
          add_action( 'personal_options_update', 'fb_save_custom_user_profile_fields' );
          add_action( 'edit_user_profile_update', 'fb_save_custom_user_profile_fields' );
      

      【讨论】:

        猜你喜欢
        • 2018-07-15
        • 1970-01-01
        • 2011-03-20
        • 2017-04-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-05
        • 2015-01-05
        相关资源
        最近更新 更多