add_rewrite_rule – Additional subpages for author pages

Which works great when going to this URL: http://mylocalsite.site/?author=1&author_view=pinboard Yes, and that is because in that URL, the author value is a user ID. But in the “pretty” version of that URL (e.g. http://mylocalsite.site/author/admin/pinboard), WordPress uses the user’s “nice name” (from the user_nicename column in the wp_users table) which by default is the same as … Read more

Custom URL rewrites work, but break my permalinks

Well I solved it – in a rather unsatisfactory way – by explicitly re-defining the default posts rule in my own code. i.e. $rewrite_keywords_structure = $wp_rewrite->root.”/%year%/%monthnum%/%postname%/”; ..etc.. I don’t really understand why this is necessary, but there you go.

Optimal code for two add_rewrite_rule’s

This is the working code: add_action(‘init’, ‘rewrite_init’); // Rewrite add_action(‘query_vars’, ‘rewrite_query_vars’); add_filter(‘template_include’, ‘rewrite_template_include’); function rewrite_init(){ add_rewrite_rule(‘([^/]+)/([0-9]+)/?$’, ‘index.php?catname=$matches[1]&currentpage=$matches[2]’, ‘top’); add_rewrite_rule(‘cam/([^/]+)/?$’, ‘index.php?name=cam&perf=$matches[1]’, ‘top’); } function rewrite_query_vars($query_vars){ $query_vars[] = ‘currentpage’; $query_vars[] = ‘catname’; $query_vars[] = ‘perf’; return $query_vars; } function rewrite_template_include($template){ if(get_query_var(‘currentpage’) || get_query_var(‘catname’)){ $template = locate_template(array(‘category.php’)); } elseif(get_query_var(‘perf’)){ $template = locate_template(array(‘single.php’)); } return $template; }

Simple page URL rewrite with add_rewrite_rule()

The second argument of add_rewrite_rule is not a path, it the query string you want WordPress executes. This should work for example.com/sub-folder/thepage/ (change page_id with ID of your page): add_rewrite_rule(‘thepage/’, ‘index.php?page_id=12’); or with page slug: add_rewrite_rule(‘thepage/’, ‘index.php?pagename=thepage’); As you have WordPress in a subdirectory and you want to rip out the directoy name, you have … Read more

Does it still make sense using json endpoint ep_mask now that there’s the new rest api? [closed]

I think you should stop using rewrite endpoints to handle JSON responses. Instead you can and you should use the REST API. So, instead of this: function makeplugins_add_json_endpoint() { add_rewrite_endpoint( ‘json’, EP_PERMALINK | EP_PAGES ); } add_action( ‘init’, ‘makeplugins_add_json_endpoint’ ); And then handle the JSON response at your own, you can and you should do … Read more

Rewrite rule : custom post type with 2 numeric variiables

add_rewrite_rule() cannot automatically create that permalink structure for you. You should use wp_link_pages_link filter. E.g: add_filter(‘wp_link_pages_link’, function($link, $i) { global $post, $photo_id; if ($photo_id && ‘gallery’ === $post->post_type) $link = $link . “https://wordpress.stackexchange.com/” . intval($photo_id) . “https://wordpress.stackexchange.com/”; return $link; }, PHP_INT_MAX, 2); Then, you must use add_rewrite_tag() to make WordPress aware of photo query string: … Read more

Optional all capture groups in rewrite rule

Ok after 4 hours I managed to make it work function pl_add_rewrite_rule() { // this works with pagination too add_rewrite_rule(‘^slike(\/([a-z]+))?(\/([a-z]+))?(\/page\/([0-9]+))?$’,’index.php?page_id=45893&carstvo=$matches[2]&kategorija=$matches[4]&paged=$matches[6]’,’top’); add_rewrite_tag(‘%carstvo%’,'([^/]*)’); add_rewrite_tag(‘%kategorija%’,'([^/]*)’); } add_action(‘init’, ‘pl_add_rewrite_rule’, 10, 0);

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)