New answers tagged

0

I think you may be mixing up a couple of concepts here. Use the new template page you made and name it archive-portfolio.php. This will display all portfolio post types in your new template at yoursite.com/portfolio and the url for the portfolio items should take care of itself. They will still be at yoursite.com/portfolio/item1 so no need to change the ...


1

You need to use %cities% (matching the name of the taxonomy). I thought that %city% was just a placeholder with a random name. Not quite - it's called a permalink structure (permastruct) and is used to map to a regular expression. When you call register_taxonomy, it automatically registers a new permastruct with the same name as the taxonomy. Read up ...


0

Seems like I just need to set has_archive to a string instead of true with the desired slug, in my case archive/dogs. Then, create a page with the dogs slug and set the desired template to it.


2

I found solution! A Monkeyman Rewrite Analyzur plugin was very helpful: https://wordpress.org/plugins/monkeyman-rewrite-analyzer/ So now, I have such working urls... single.php: /magazine-name/issue-year/issue/article-name archive.php: /magazine-name/issue-year/issue /magazine-name/issue-year /magazine-name On a custom post editor page in wp-admin I ...


0

In the wp_option table, I change site_url and home to the new url, but I forgot to prefix http:// In case it happens to somebody else, it could save you hours !!!


0

As someone else suggested, I reactivated my theme and it started working!


4

Since it is a performance question, you might be able to avoid using meta keys at all by storing/getting that data another way and not having to set a separate meta field to match with... a. You could get the year from the published $post->post_date... So that when doing the query just use the date argument: $args = array( 'post_type' => $...


0

I eventually managed to find a solution: First of all, the pre_get_posts action that I originally had wasn't good, because both the events and the posts are displayed using the same template (taxonomy-event-category.php). The code that I wrote in pre_get_posts forced wordpress to display only events in that template, so I removed it. I replaced it with ...


0

To do what you want you are going to have to add_rewrite_rule for each rule you have. I am storing new rules that users add to an options array. If the user wants to delete the rule, then once selected, I unset it from the array. function remove_rule($user_input){ foreach($rules as $key => $rule){ if($rule === $user_input){ unset(...


2

1. Change new_category taxonomy's rewrite rule while registering: 'rewrite' => ['hierarchical' => false, 'with_front' => false, 'slug' => 'news'] Make sure rewrite rule of news post type is default or: 'rewrite' => ['slug' => false, 'with_front' => false] 2. Add rewrite rules for new_category: add_action('init', function() { ...


3

If you'd like to keep your slugs for SEO, then you'll want to define a new rewrite tag and leave the default behavior for post slugs. If you'd like a unique id, then instead of looking up possible duplicates, why not just re-use the post ID which is guaranteed to be unique given a MySQL primary index – you can convert it to a base36 number if you want it to ...


2

This is why you need to add rewrite rules on the init action on every request, as well as on plugin activation. When your plugin deactivation hook is run, other plugin init hooks have already run, so their rules exist in the global variable that stores them for the life of each request. Flushing rewrite rules empties the option that stores the rules long-...


2

1. Add a new rewrite rule: add_action('init', function() { add_rewrite_rule('^dog/([^/]+)/?$', 'index.php?cat=dog&name=$matches[1]', 'top'); }, 10, 0); 2. Filter the post link: add_filter('post_link', function($post_link, $post, $leave_name = false, $sample = false) { if ( is_object_in_term($post->ID, 'category', 'DOG') ) { $...


2

I can't really think of a way that you would have a post type of page and have it be "repeatable." As Jake said, it's going to involve rewrite rules. I think the easiest way to do it would be to set up some templates for whatever these cases may be in your theme directory, and make use of query vars to populate them. So, for example: function ...


1

I can't really think of an easy and repeatable way to do this, but check out: https://wordpress.org/support/topic/create-static-subpage-for-a-custom-post-type You can create a custom parameter at the end of your post type. Once you get this you can load a template and use that parameter to query the page's content.


0

I had thought I would just comment on it but then it would be too small a place to specify the details. The answer posted by Jan Fabry works nicely! However the drawback of this is, which he even pointed out in the comments is that if you have a URL like http://example.com/sports/world-sports/permalink, it will be stripped down to http://example.com/world-...



Top 50 recent answers are included