Rewrite rule taxonomy url with different values in one function

You can do that using a subpattern or capturing group like ([a-z]) in your rewrite rule’s regex (i.e. regular expression pattern, which is the 1st parameter for add_rewrite_rule()), and then use $matches[<n>] in your query (the 2nd parameter for add_rewrite_rule()), where <n> is a number (1 or above) and it’s the subpattern’s position number. Why … Read more

Custom slugs with dates & IDs on Custom Post Type

Yes, it’s not hard to do that. Just register your post type and enable rewriting for that post type, i.e. set rewrite to true. Once registered, modify its permalink structure like so: global $wp_rewrite; $wp_rewrite->extra_permastructs[‘<post type>’][‘struct’] = ‘<your structure here>’; Use the post_type_link filter to replace rewrite tags like %post_id% in the permalink URL. If … Read more

Load posts via AJAX without draft status

admin-ajax.php is treated as part of the admin, so protected statuses will be included. To solve this just explicitly define post_status as publish to only get published posts: $args = array( ‘post_type’ => ‘project’, ‘post_status’ => ‘publish’ ); Or, better yet, consider using the REST API for AJAX requests, instead of the aging admin-ajax.php approach. … Read more

How to make posts under custom post type not generate a URL / post

Looking at the class and function you’re using, this method is a little problematic: public function buildPostArgs( $slug, $singular=”Post”, $plural=”Posts”, $args = array() ) { $args = wp_parse_args($args, $this->postDefaults); $args[‘rewrite’][‘slug’] = $slug; $args[‘labels’] = $this->buildPostLabels($singular, $plural); return $args; } If we ignore your problem, $args[‘rewrite’][‘slug’] is going to generate a PHP warning if you set … Read more