Nested custom post types with permalinks

If you want to keep ‘authors’ as the base slug in the permalinks, i.e. example.com/authors/stephen-king/ for the ‘authors’ CPT, example.com/authors/stephen-king/the-shining/ for the ‘books’ CPT and example.com/authors/stephen-king/the-shining/chapter-3/ for the ‘chapters’ CPT, WordPress will think pretty much everything is an ‘authors’ post or a hierarchical child of an ‘authors’ post and, since that is not the case, … Read more

Get current URL (permalink) without /page/{pagenum}/

You can get the current URL through home_url( $wp->request ). Try the example below: global $wp; // get current url with query string. $current_url = home_url( $wp->request ); // get the position where ‘/page.. ‘ text start. $pos = strpos($current_url , ‘/page’); // remove string from the specific postion $finalurl = substr($current_url,0,$pos); echo $finalurl;

WordPress matching URLs with trailing tildes

Let’s go simple If I understand OP well, your problem is that urls containing a tilde are matched at all. All other answers focus on the fact that sanitization for query strips out some characters before perform the query, however one should be capable to prevent a rewrite rule to don’t match under some circumstances. … Read more

Shouldn’t this be easy?! Custom post type/custom taxonomy permalink

Follow the advice on this question as you did already, but add this to your code: add_action( ‘generate_rewrite_rules’, ‘fix_literature_category_pagination’ ); function fix_literature_category_pagination( $wp_rewrite ) { unset($wp_rewrite->rules[‘literature/([^/]+)/page/?([0-9]{1,})/?$’]); $wp_rewrite->rules = array( ‘literature/?$’ => $wp_rewrite->index . ‘?post_type=literature’, ‘literature/page/?([0-9]{1,})/?$’ => $wp_rewrite->index . ‘?post_type=literature&paged=’ . $wp_rewrite->preg_index( 1 ), ‘literature/([^/]+)/page/?([0-9]{1,})/?$’ => $wp_rewrite->index . ‘?literature_category=’ . $wp_rewrite->preg_index( 1 ) . ‘&paged=’ . … Read more

How to change permalink structure for custom post type and it’s taxonomies?

Ok I think I might have a solution. I have no idea if this is the right way to accomplish this, but as for now it’s the only thing that seems to work. add_filter(‘rewrite_rules_array’, ‘mmp_rewrite_rules’); function mmp_rewrite_rules($rules) { $newRules = array(); $newRules[‘portfolio/(.+)/(.+?).html$’] = ‘index.php?project=$matches[2]’; $newRules[‘portfolio/(.+)/?$’] = ‘index.php?project_category=$matches[1]’; return array_merge($newRules, $rules); } add_filter(‘request’, ‘mmp_rewrite_request’); function mmp_rewrite_request($vars) … Read more

What is the difference between get_post_permalink and get_permalink?

The get_post_permalink() funciton fetches the link to a post depending on its “permanent” link plus your custom rewrite rules that changes ?p=123 into for e.g. my-beautiful-sunday-diary. The get_permalink() function is more “basic” but as well more versatile in what it does: For a post_type of page, it uses get_page_link() attachment, it uses get_attachment_link() post, it … Read more

Add .html (dot HTML) extension to custom post types

This seem to work: Create the rewrite rules like post-type/post-name.html. You can use arrays to create the rules for just some set of post types instead of doing it for all of them. add_action( ‘rewrite_rules_array’, ‘rewrite_rules’ ); function rewrite_rules( $rules ) { $new_rules = array(); foreach ( get_post_types() as $t ) $new_rules[ $t . ‘/([^/]+)\.html$’ … Read more

deneme bonusu veren sitelerbahis casinomakrobetceltabetpinbahispolobetpolobet girişpinbahis girişmakrobet girişpulibet girişmobilbahis girişkolaybet giriş