Hot answers tagged

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' => $...


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 ...


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 ...


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() { ...


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 ...


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.



Only top voted, non community-wiki answers of a minimum length are eligible