【问题标题】:Wordpress suggest with key value pair in adminWordpress 建议在管理员中使用键值对
【发布时间】:2015-05-05 21:27:36
【问题描述】:

我有一个元框,其中有一个文本框,用于获取自定义帖子类型的标题列表。到目前为止它工作正常,但问题是我找不到使用 wordpress 内置建议插件实现键/值自动完成的方法。这是我的代码

/**
 * Return list of artists for autocomplete. .
 *
 * @since    1.0.0
 */
public function list_artists() {
    // This only send the post titles not the id
    foreach($result as $k => $v) {
       echo $v . "\n";
    }

    // This doesn't work and sends the whole text as json string 
    $results = array(1 => 'Raheel', 2 => 'Zain', 3 => 'Vicky');
    echo json_encode($results);
    die();
  }

/**
 * Provide a dashboard view for the plugin
 *
 * This file is used to markup the public-facing aspects of the plugin.
 *
 * @link       http://example.com
 * @since      1.0.0
 *
 * @package    Songs_Cloud
 * @subpackage Songs_Cloud/admin/partials
 */

function show_album_meta_box() { ?>
    <label for="artist">Artist</label>
    <input type="text" id="artist" name="artist">
    <script type="text/javascript">
        jQuery(function($) {
        $("#artist").suggest(ajaxurl + "?action=sc_list_artists", { delay: 500, minchars: 2 });
        });
    </script>
<?php }

我不愿意使用下拉菜单,因为可能有 1000 个艺术家,而且在管理部分看起来不太好。

是否有可能使用建议插件或我可以使用的任何其他方法来实现这一点?

【问题讨论】:

    标签: php autocomplete wordpress


    【解决方案1】:

    我想我应该使用Select2

    这样,我将动态绑定下拉列表并加载 select2 插件,以便它为管理部分提供一个漂亮的界面,而不是长下拉列表。

    【讨论】:

    • 请使用您问题上的编辑链接添加其他信息。 “发布答案”按钮应仅用于问题的完整答案。
    • @rink.attendant.6 现在好吗?
    猜你喜欢
    • 2015-01-25
    • 1970-01-01
    • 2021-04-04
    • 2020-06-18
    • 2017-12-31
    • 1970-01-01
    • 2016-08-15
    • 1970-01-01
    • 2011-03-12
    相关资源
    最近更新 更多