Custom Post type permalink structure with custom_post_id

THE ANSWER First of all, this link helped me a lot https://premium.wpmudev.org/blog/building-customized-urls-wordpress It turned out the I don’t need to use add_rewrite_tag(), but to use add_rewrite_rule() to achieve my goal. I wondered why — %job_id% (or even %post_id%, tried them both) is not recognized in my permalink structure. I was expecting that %job_id% will be … Read more

How to delete unused URL?

Whenever you change the slug of a permalink on posts ( and custom post types with post capabilities ), WordPress will save the old slug in the post_meta table with the key _wp_old_slug. On a normal installation the old slug should redirect to the new slug using wp_old_slug_redirect(). There are a couple ways to remove … Read more

Custom page slug without creating a WP page

You’re close, the query var for passing page slug is pagename: add_filter(‘query_vars’, ‘add_account_edit_var’, 0, 1); function add_account_edit_var($vars){ $vars[] = ‘account-edit’; return $vars; } add_action( ‘init’, ‘add_account_edit_rule’ ); function add_account_edit_rule() { add_rewrite_rule( ‘^my-account/([^/]*)/?’, ‘index.php?pagename=my-account&account-edit’, ‘top’ ); } To capture the value in your rule, you need to pass the value in $matches[1]: add_rewrite_rule( ‘^my-account/([^/]*)/?’, ‘index.php?pagename=my-account&account-edit=$matches[1]’, ‘top’ … Read more

Remove query string specific key value

[EDIT] This should work the way you wanted it to: $marca = get_query_var(‘marca’); $marca_arg = isset($marca) && is_array($marca) ? $marca : []; $url_base = remove_query_arg( ‘marca’ ); $n = count( $marca_arg ); foreach ($marcas_terms as $marca_term) { $selected = in_array( $marca_term->slug, $marca_arg ); if ( $selected ) { $marca_arg2 = array_diff( $marca_arg, [ $marca_term->slug ] … Read more

Why does wp_redirect strip out %0A (url encoded new line character) and how do I make it stop?

If you take a look to the wp_sanitize_redirect() function you will notice it is removing the new lines from the destination URL: https://core.trac.wordpress.org/browser/tags/4.9/src/wp-includes/pluggable.php#L1249 In my opinion you have 2 options: 1 – Convert new lines on the message to a diff allowed unique char combination and then replace them back to new lines before outputting … Read more

Extract subdomain and relative address from a url

I encountered a similar requirement, and could not find a ready-made solution for this, so I created a function that is based on the standard PHP function parse_url() and added to this over time to extract everything that I could think of. Below is my code and two examples of the output. This will extract … Read more

CSS not loaded when omitting www. part of URL

This can happen for several reasons – in your case, it looks like you are using a caching plugin that only recognizes www links. I suspect if you turned off caching you would not have that problem, but then you’d lose the benefits of caching. It’s best practice (with or without caching) to add redirects … Read more

Special domain for a page

There is a plugin that does exactly this: https://wordpress.org/plugins/multiple-domain-mapping-on-single-site Anyway, it would be nicer to have things under control with an understandable few lines of script, so I’m still open to answers

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