Question

I followed the following to set up a plugin for custom post types: https://kinsta.com/blog/wordpress-custom-post-types/#register

But i am getting the error: Parse error: syntax error, unexpected '', $args ); ' (T_CONSTANT_ENCAPSED_STRING), expecting ')' in D:\xampp\htdocs\simplerPR\wp-content\plugins\goldnuggs-custom-post-type\goldnuggs-cpt.php on line 48

Can anyone see my mistake?

 <?php
/*
Plugin Name: Register Custom Post Types

*/

function goldnuggs_register_post_type() {
    $labels = array(
 'name' => __( ‘Case-studies’, ‘goldnuggs’ ),
 'singular_name' => __( 'Case Study', ‘goldnuggs’ ),
 'add_new' => __( 'New Case Study', ‘goldnuggs’ ),
 'add_new_item' => __( 'Add New Case Study', ‘goldnuggs’ ),
 'edit_item' => __( 'Edit Case Study', ‘goldnuggs’ ),
 'new_item' => __( 'New Case Study', ‘goldnuggs’ ),
 'view_item' => __( 'View Case Studies', ‘goldnuggs’ ),
 'search_items' => __( 'Search Case Studies', ‘goldnuggs’ ),
 'not_found' =>  __( 'No Case Studies Found', ‘goldnuggs’ ),
 'not_found_in_trash' => __( 'No Case Studies found in Trash', ‘goldnuggs’ ),
);

$args = array(
 'labels' => $labels,
 'has_archive' => true,
 'public' => true,
 'hierarchical' => false,
 'supports' => array(
  'title',
  'editor',
  'excerpt',
  'custom-fields',
  'thumbnail',
  'page-attributes'
 ),
 'taxonomies' => 'category',
 'rewrite'   => array( 'slug' => 'case-study' ),
 ‘show_in_rest’ => true
);

register_post_type( ‘goldnugg_case', $args );

}
add_action( 'init', 'goldnuggs_register_post_type' );

Any help would be appreciated!

Was it helpful?

Solution

The problem is your code is using 'Curley quotes' which is probably something the tutorials cms converted automatically (WordPress...).

‘show_in_rest’ => true

You need to change these to single quotes:

'show_in_rest' => true

Full code:

<?php
/*
Plugin Name: Register Custom Post Types

*/

function goldnuggs_register_post_type() {
    $labels = array(
        'name' => __( 'Case-studies', 'goldnuggs' ),
        'singular_name' => __( 'Case Study', 'goldnuggs' ),
        'add_new' => __( 'New Case Study', 'goldnuggs' ),
        'add_new_item' => __( 'Add New Case Study', 'goldnuggs' ),
        'edit_item' => __( 'Edit Case Study', 'goldnuggs' ),
        'new_item' => __( 'New Case Study', 'goldnuggs' ),
        'view_item' => __( 'View Case Studies', 'goldnuggs' ),
        'search_items' => __( 'Search Case Studies', 'goldnuggs' ),
        'not_found' =>  __( 'No Case Studies Found', 'goldnuggs' ),
        'not_found_in_trash' => __( 'No Case Studies found in Trash', 'goldnuggs' ),
    );

    $args = array(
        'labels' => $labels,
        'has_archive' => true,
        'public' => true,
        'hierarchical' => false,
        'supports' => array(
            'title',
            'editor',
            'excerpt',
            'custom-fields',
            'thumbnail',
            'page-attributes'
        ),
        'taxonomies' => 'category',
        'rewrite'   => array( 'slug' => 'case-study' ),
        'show_in_rest' => true
    );

    register_post_type( 'goldnugg_case', $args );

}
add_action( 'init', 'goldnuggs_register_post_type' );
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top