WordPress.org

Ready to get started?Download WordPress

Forums

Trouble using Taxonomies (5 posts)

  1. maycontainweasel
    Member
    Posted 1 year ago #

    Hey everyone

    Really glad to join the forum hope to meet some good people here :)
    i'm new to wordpress but i have experience with joomla

    i was reading this article on the codex, on custom taxonomies

    http://codex.wordpress.org/Taxonomies#Custom_Taxonomies

    When i try placing the example taxonomy code into my functions.php file i get this error,

    Fatal error: Call to undefined function add_action() in C:\wamp\www\temp-wp\flamingweasel\wp-includes\functions.php on line 3645

    This is the function code

    function people_init() {
    	// create a new taxonomy
    	register_taxonomy(
    		'people',
    		'post',
    		array(
    			'label' => __( 'People' ),
    			'rewrite' => array( 'slug' => 'person' ),
    			'capabilities' => array('assign_terms'=>'edit_guides', 'edit_terms'=>'publish_guides')
    		)
    	);
    }
    add_action( 'init', 'people_init' );

    i'm running my site in wamp, is there something i need to enable in order to make it work?
    what am i doing wrong here?

    Thanks alot in advance

    Mike

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    Hi maycontainweasel

    I think you put the code in the wrong functions.php file. You have to put it in the functions.php file in your theme folder:
    wp-content/themes/yourtheme/functions.php. If your theme doesn't have a file called functions.php you can create one with a text editor and put the code in there.

    Remove the code from the functions.php file in the wp-includes folder.

  3. cinghaman
    Member
    Posted 1 year ago #

    add_action( 'init', 'register_taxonomy_peoples' );
    
    function register_taxonomy_peoples() {
    
        $labels = array(
            'name' => _x( 'Peoples', 'peoples' ),
            'singular_name' => _x( 'People', 'peoples' ),
            'edit_item' => _x( 'Edit People', 'peoples' ),
            'update_item' => _x( 'Update People', 'peoples' ),
            'add_new_item' => _x( 'Add New People', 'peoples' ),
            'add_or_remove_items' => _x( 'Add or remove peoples', 'peoples' ),
            'menu_name' => _x( 'Peoples', 'peoples' ),
        );
    
        $args = array(
            'labels' => $labels,
            'public' => true,
            'show_in_nav_menus' => true,
            'show_ui' => true,
            'show_tagcloud' => true,
            'hierarchical' => true,
    
            'rewrite' => true,
            'query_var' => true
        );
    
        register_taxonomy( 'peoples', array('post'), $args );
    }

    should be something like this

  4. maycontainweasel
    Member
    Posted 1 year ago #

    Hey thanks so much for the replays everyone, very much appreciated,
    i was indeed using the wrong functions.php file! :)

  5. maycontainweasel
    Member
    Posted 1 year ago #

    Thanks Robin i'll try that out now!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.