WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Getting custom taxonomies (4 posts)

  1. mediabaron
    Member
    Posted 3 years ago #

    I'm trying to add to an existing plugin for output to a sitemap to include a custom taxonomy.

    I registered a taxonomy in the functions.php file, not sure if I did it right as I'm new to dealing with this. Here's what I have

    function create_my_taxonomies() {
    register_taxonomy('genres', 'post', array(
    'hierarchical' => false, 'label' => 'Genres',
    'query_var' => true, 'rewrite' => true));
    }
    add_action('init', 'create_my_taxonomies', 0);

    Now I'd like to pull the taxonomy data into the sitemap

    $xmlOutput.= "\t\t\t\t<news:genres>";
    		$xmlOutput.= get_the_term_list( 'post_genres' );
    		$xmlOutput.= "</news:genres>\n";

    This code is obviously wrong and was wondering if someone could enlighten me into how I'm supposed to get the genres for population into that second line immediately above. I've gone through plugin guides and such but they all show code to insert the URI, text and taxonomy. I just want the taxonomy term or terms in there.

  2. mediabaron
    Member
    Posted 3 years ago #

    Okay, tried modifying the code, still doesn't quite work. Here's what I come up with.

    For functions.php

    //START Custom Taxonomy for Genres
    add_action( 'init', 'create_my_genres' );
    function create_my_genres() {
     $labels = array(
        'name' => _x( 'Genres', 'taxonomy general name' ),
        'singular_name' => _x( 'Genre', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Genres' ),
        'all_items' => __( 'All Genres' ),
        'parent_item' => __( 'Parent Genre' ),
        'parent_item_colon' => __( 'Parent Genre:' ),
        'edit_item' => __( 'Edit Genre' ),
        'update_item' => __( 'Update Genre' ),
        'add_new_item' => __( 'Add New Genre' ),
        'new_item_name' => __( 'New Genre' ),
      ); 	
    
    register_taxonomy('genre', 'post', array(
      'hierarchical' => true,
      'labels' => $labels
    ));
    }
    //END Custom Taxonomy for Genres

    And for the plugin file:

    //START GENRES
    	        $xmlOutput.= "\t\t\t<news:genres>";
    		$xmlOutput.= strip_tags( get_the_term_list( $post->ID, 'genre', '', '', '' ) );
    		$xmlOutput.= "</news:genres>\n";
    		//END GENRES

    It now pulls Genres and outputs without the hyperlinking. The problem is that it isn't post specific and it just pulls the genre for the last published post, tagging every single post with that genre in the sitemap.

    Still stumped. I tried contacting the plugin author with no response which is why I tried taking this on myself.

  3. mediabaron
    Member
    Posted 3 years ago #

    Okay, found a better plugin Google XML News Sitemap plugin. Resolved.

  4. mediabaron
    Member
    Posted 3 years ago #


Topic Closed

This topic has been closed to new replies.

About this Topic