Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/421.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Wordpress常见问题解答手风琴自定义帖子类型-匿名函数问题_Javascript_Php_Jquery_Wordpress - Fatal编程技术网

Javascript Wordpress常见问题解答手风琴自定义帖子类型-匿名函数问题

Javascript Wordpress常见问题解答手风琴自定义帖子类型-匿名函数问题,javascript,php,jquery,wordpress,Javascript,Php,Jquery,Wordpress,我想在我的wordpress站点中以手风琴风格显示常见问题解答自定义帖子类型,我在这里找到了一个如何执行此操作的教程: 我在functions.php中添加了所有代码: /* Register the Custom Post Type */ add_action('init', function() { $labels = array( 'name' => _x('FAQ', 'post type general name'), 'singula

我想在我的wordpress站点中以手风琴风格显示常见问题解答自定义帖子类型,我在这里找到了一个如何执行此操作的教程:

我在functions.php中添加了所有代码:

/* Register the Custom Post Type */

add_action('init', function() {

    $labels = array(
        'name' => _x('FAQ', 'post type general name'),
        'singular_name' => _x('Question', 'post type singular name'),
        'add_new' => _x('Add New Question', 'Question'),
        'add_new_item' => __('Add New Question'),
        'edit_item' => __('Edit Question'),
        'new_item' => __('New Question'),
        'all_items' => __('All FAQ Questions'),
        'view_item' => __('View Question'),
        'search_items' => __('Search FAQ'),
        'not_found' => __('No FAQ found'),
        'not_found_in_trash' => __('No FAQ found in Trash'),
        'parent_item_colon' => '',
        'menu_name' => 'FAQ'
    );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'has_archive' => true,
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title', 'editor', 'page-attributes')
    );
    register_post_type('FAQ', $args);
});

add_action( 'wp_enqueue_scripts', 'wptuts_enqueue' );
function wptuts_enqueue() {
    wp_register_style('wptuts-jquery-ui-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/themes/south-street/jquery-ui.css');
    wp_enqueue_style('wptuts-jquery-ui-style');

    wp_register_script('wptuts-custom-js', get_template_directory_uri() . '/faq/faq.js', 'jquery-ui-accordion', '', true);
    wp_enqueue_script('wptuts-custom-js');
}

add_shortcode('faq', function() {

    $posts = get_posts(array(  //Get the FAQ Custom Post Type
        'numberposts' => 10,
        'orderby' => 'menu_order',
        'order' => 'ASC',
        'post_type' => 'faq',
    ));

    $faq  = '<div id="wptuts-accordion">'; //Open the container
    foreach ( $posts as $post ) { // Generate the markup for each Question
        $faq .= sprintf(('<h3><a href="">%1$s</a></h3><div>%2$s</div>'),
            $post->post_title,
            wpautop($post->post_content)
        );
    }
    $faq .= '</div>'; //Close the container

    return $faq; //Return the HTML.
});
我得到了一个错误:

Uncaught TypeError: undefined is not a functionfaq.js?ver=4.1:2 (anonymous function)faq.js?ver=4.1:3 (anonymous function)
如何解决这个问题,我做错了什么?我检查了我的主机,我使用的是最新的PHP版本,因为我认为这可能是问题所在


谢谢

我认为问题在于wp\u register\u脚本('wptuts-custom-js',get\u template\u directory\u uri()。/faq/faq.js',jquery ui accordion','',true)

wp\u register\u script
函数(即dependecies)的第三个参数必须是数组。请尝试替换此参数

wp\u register\u script('wptuts-custom-js',get\u template\u directory\u uri()。/faq/faq.js',array('jquery-ui-accordion'),'',true)

您还将
jquery ui accordion
设置为此脚本的从属项,但代码中没有名为
jquery ui accordion
的脚本。您还必须注册该脚本才能完成此工作

更多信息,请查看法典

Uncaught TypeError: undefined is not a functionfaq.js?ver=4.1:2 (anonymous function)faq.js?ver=4.1:3 (anonymous function)