custom post type plugin error

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:xampphtdocssimplerPRwp-contentpluginsgoldnuggs-custom-post-typegoldnuggs-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!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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' );


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x