WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] noob custom post type question (2 posts)

  1. jonsaul
    Member
    Posted 1 year ago #

    Hello,

    this is my first post and I am new to wordpress, but very much enjoying working with it.

    I have a question regarding my custom posts type defined as so...

    // Add new post type for Portfolio
    add_action('init', 'portfolio_init');
    function portfolio_init()
    {
    	$portfolio_labels = array(
    		'name' => _x('Portfolio', 'post type general name'),
    		'singular_name' => _x('Portfolio', 'post type singular name'),
    		'all_items' => __('All projects'),
    		'add_new' => _x('Add new project', 'projects'),
    		'add_new_item' => __('Add new project'),
    		'edit_item' => __('Edit project'),
    		'new_item' => __('New project'),
    		'view_item' => __('View project'),
    		'search_items' => __('Search in portfolio'),
    		'not_found' =>  __('No projects found'),
    		'not_found_in_trash' => __('No projects found in trash'),
    		'parent_item_colon' => ''
    	);
    	$args = array(
    		'labels' => $portfolio_labels,
    		'public' => true,
    		'publicly_queryable' => true,
    		'show_ui' => true,
    		'query_var' => true,
    		'rewrite' => true,
    		'capability_type' => 'post',
    		'hierarchical' => false,
    		'menu_position' => 5,
    		'supports' => array('title','editor','thumbnail','excerpt'),
    		'has_archive' => 'projects'
    	);
    	register_post_type('portfolio',$args);
    }

    I am using the awesome Advanced custom fields plugin for my write panels, and all is workign fine, apart from when I go to http://www.mysite.com/portfolio/ I would like to see the archive, but at the moment i can only see it on http://www.mysite.com/projects/, ??

    When I view a post from my custom posts type it will create a url such as http://www.mysite.com/portfolio/my-post-title/

    I have a feeling I can change this in

    'has_archive' => 'projects'

    portion of my code but when I do nothing happens, I have a feeling i need to make some kind of flush function ?? but I cant work out if this is the case, or how to do that so far...

    Basically, my custom post type is called 'Portfolio', I want to have a link on my site that takes me to http://www.mysite.com/portfolio/ where I can see all posts for that type, and http://www.mysite.com/portfolio/my-post-title/ for the single view (which works fine)
    but why cant I have an archive at http://www.mysite.com/portfolio/ instead of http://www.mysite.com/projects/ which does actually produced a list of posts from my post type ??? HELP!!

  2. jonsaul
    Member
    Posted 1 year ago #

    ok, sorry i've solved this.

    I realised updating and re-saving the permalinks settings has the desired effect of updating the functions file with my new archive location.

Topic Closed

This topic has been closed to new replies.

About this Topic