I'm using tribe events in wordpress and been struggling with the following problem:
I have events (custom post type) filtered by category (default taxonomy for this plugin).
I'm using "pretty permalinks settings" so my url looks like that:
[website.com]/events/category/Amsterdam/ (when my category is Amsterdam).
And now to the question:
I sub filtered my posts by another custom taxonomy called “event_type” (concert, pub …)
when I'm trying to get all the posts from Amsterdam that are a "concert" type, my url is:
[website.com]/events/category/amsterdam/?event_type=concert
on default permalink settings the url is:
[website.com]/index.php?tribe_events_cat=amsterdam&event_type=concert
How do I get WordPress to transform and to recognize my url as:
[website.com]/events/category/amsterdam/event_type/concert/
I know it has something to do with the rewrite_rules_array but could not manage to do so.
Any help would be very appreciated!
Thanx in advance.
While You register custom post type:
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' );
checkout the "rewrite" parameter. More You can check here:
http://codex.wordpress.org/Function_Reference/register_taxonomy
Also sometimes You need to flush permalink structure by going to permalink settings and clicking save (dont ask me why) ;).
Related
I have a Custom Taxonomy called movie-genres
'rewrite' => array('slug' => 'movie-genres', 'with_front' => true) );
register_taxonomy( 'movie-genres', array( 'movies' ), $args );
And I have a WP template hierarchy for the Taxonomy and it's associated Terms like below
archive.php
archive-movie-genres.php
taxonomy.php
taxonomy-movie-genres.php
taxonomy-movie-genres-action.php
Now when navigating in the browser I am able to see the CPTs listed for term of action like this
domain.com/movie-genres/action
but when landing at movie-genres to get the all terms listed under this taxonomy like
domain.com/movie-genres/
I am getting the 404 page in return!
As you can see I have the archive-movie-genres.php and taxonomy-movie-genres.php created. Why am I getting ended at 404?
I have created a CPT and several custom taxonomies applied to this CPT.
At the moment my URL are as follow (using a plugin) :
www.example.com/[cpt]/[taxonomy-term]/post
For a specific cpt, I'd like to move to :
www.example.com/[taxonomy-term]/post
How can I achieve that ?
If you wanna have custom slug without [cpt] for the custom post_type, you need to pass this value in args array
$args['rewrite'] = array(
'slug' => 'your-custom-post-type',
'with_front' => false,
),
and after this update your permalinks
I have a custom post type named 'The Books', and a relative category named 'The Books' for these custom posts.
When I add the category The Posts to my nav menu, it doesn't work because it goes to the URL /category/the-books instead of just going to /the-books. If I posted this in the default post section it shows correctly, but when I post in the custom post section it does not return my post. I can, of course, add individual posts from my custom post section to the nav menu, but can't figure out how to add an archive page of the custom posts.
My permalinks are set to: URL/%postname%/ so I'm not sure why that is happening.
Here's the function for my custom posts:
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'hpl_books',
array(
'labels' => array(
'name' => __( 'The Books' ),
'singular_name' => __( 'Book' )
),
'taxonomies' => array('category'),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'the-books'),
)
);
}
Any advice is greatly appreciated.
thanks!
You shouldn't need to add a category "the-books" in order to display the results.
Have you created a view in your page-templates directory called "archive-hpl_books.php?" That's the file WordPress will look for to display the archive of your custom post type. Basically, you would create a page called "the-books" or whatever, then set archive-hpl_books.php as the template.
See http://codex.wordpress.org/Template_Hierarchy
I'm only responding to this because I just went through a similar issue, so I'm down to help out. :)
I'm customizing the admin on a new WP site, and I am creating an over-arching custom post type, that will allow the admin to create pages for the site. I want them to be able to pull values from other custom post types and set them here. I'm struggling to find good documentation on how to do this though. I can create multiple custom post types without a problem, just unsure how to pull the values of post_type_y into the meta_options for post_type_x.
Any and all help is appreciated!
Since I can't 'comment' on your question, I'll do my best to answer it as I understand it..
There's a plugin posts to posts that will allow you to associate Post 1 with Post 2. It's a little clunky, but gets the job done.
If you're looking to associate tags, categories or whatever between multiple post-types, I prefer using custom taxonomies as they are relatively easy to implement.
Sample Custom Taxonomy:
function languages_init() {
// create a new taxonomy
register_taxonomy(
'languages',
array('post','clients','positions','projects'), // Set various post-types
array(
'label' => __( 'Languages' ),
'sort' => true,
'args' => array( 'orderby' => 'term_order' ),
'rewrite' => array( 'slug' => 'language' )
)
);
}
add_action( 'init', 'languages_init' );
I have the following code to build a custom taxonomy for my portfolio:
add_action( 'init', 'create_pc_db_taxonomies', 0 );
function create_pc_db_taxonomies() {
register_taxonomy( 'type', 'post', array( 'hierarchical' => true, 'label' => 'Type', 'query_var' => true, 'rewrite' => array( 'slug' => 'type' ) ) );
}
I have created a portfolio category on my site (I removed the /category/ base) and have created some items and set the custom taxonomies against them. So I get the following setup:
http://domain.com/portfolio/item1/ but what I want is for the taxonomy links to look like this: http://domain.com/portfolio/type/web and then this will show a list of portfolio items related to the that type. At the moment they are root like http://domain.com/type/web these create 404's, but I have also tried adding 'portfolio/type' as the taxonomy slug but it just creates a 404 as well, but i'm pretty sure this is the wrong way of doing it anyways. Any help?
Thanks
EDIT: The site is here: http://driz.co.uk/ all the work is in a category called Portfolio and under each pic is the title and custom taxonomy (if you click on them you will get the 404)
Make sure all plugins are disabled (at least ones that tweak with rewrites), and delete the option rewrite_rules in your wp_options table.
Now remove any hooks in your theme that meddle with custom taxes and post types, and run this on init;
register_taxonomy(
'type',
'post',
array(
'hierarchical' => true,
'label' => 'Type',
'rewrite' => array('slug' => 'portfolio/type')
)
);
In your permalink settings, choose one of the default options, and make sure both a category and tag base is set, then update.
Dump $wp_rewrite as you did before, and you should see a few lines like so;
[portfolio/type/([^/]+)/page/?([0-9]{1,})/?$] => index.php?type=$matches[1]&paged=$matches[2]
[portfolio/type/([^/]+)/?$] => index.php?type=$matches[1]
These should be near the very beginning of the array, before tags, categories and the like.
Let me know how you get on!
(When I run the code in my install of WP 3.0-beta-2 it works, so I assume something funky is happening at the moment).
I'm sure you can fake a slug like that, using portfolio/type - the key is, once you've updated your code, you'll need to flush the rewrite rules.
Do this by simply re-saving your permalink settings in the admin.