SOLVED Custom Add rewrite rule and Get string

The values parsed out of internal rewrites don’t end up in GET, you have to use get_query_var(‘search_location’) instead. If you have code that you can’t edit that relies on GET, you can try to set them manually- function wpd_foo_get_param() { if( false !== get_query_var( ‘search_location’ ) ){ $_GET[‘search_location’] = get_query_var( ‘search_location’ ); } } add_action( … Read more

Rewrite author URL to example.com/u/{user_id}/{username}/

Figured it out! /** * Replace %author_id% by author_id. * * @since 1.0.0 * @param string $link * @param int $author_id */ add_filter( ‘author_link’, ‘wpse_298572_change_author_link’, 10, 2 ); function wpse_298572_change_author_link( $link, $author_id ) { $link = str_replace( ‘%author_id%’, $author_id, $link ); return $link; } /** * Rewrite the user link. * * @since 1.0.0 */ … Read more

WordPress add_rewrite_rule second argument not working

on the rewrite flush, the rewrite rule created by the custom post type overwrite yours because the target is the same. to avoid this, you can use this filter const TAXONOMY_PUBLICACOES = “publicacoes”; add_filter(TAXONOMY_PUBLICACOES . “_rewrite_rules”, function ($rules) { unset($rules[“publicacoes/(.+?)/page/?([0-9]{1,})/?$”]); return $rules; });

Create custom url which executes code (not render render a WordPress entity)?

You can achieve this with a rewrite rule, you just need to exit execution before the main query is run. First, add a query var that will get set by the rewrite rule: function wpd_query_vars( $query_vars ){ $query_vars[] = ‘my_var’; return $query_vars; } add_filter( ‘query_vars’, ‘wpd_query_vars’ ); Next, the rewrite rule: function wpd_rewrite_rule(){ add_rewrite_rule( ‘^my-url/?$’, … Read more

URL rewrite with external JSON query

You can try URL rewriting like that add_action(“wp_loaded”, function () { add_rewrite_tag(“%id%”, “([^&]+)”); add_rewrite_rule( ‘^details/[^&]+/([0-9]+)/?’, ‘index.php?id=$matches[1]&pagename=details’, ‘top’ ); }); And then flush rewrite rules cache one time in Settings -> Permalinks. With this rewriting, the identifier is no more in $_GET but you can get it with https://codex.wordpress.org/Function_Reference/get_query_var.

Custom rewrite for product variation not working

This works because on this URL, $_REQUEST[‘attribute_pa_model’] is set, and in this example, the value is iphone-x: index.php?product=example&attribute_pa_model=iphone-x But on this URL, $_REQUEST[‘attribute_pa_model’] is not set, so the auto-selection of the product variation does not work: /product/example/iphone-x So on that URL, you can use the woocommerce_dropdown_variation_attribute_options_args to filter the selected value, like so: add_filter( ‘woocommerce_dropdown_variation_attribute_options_args’, … Read more

custom permalink for single post category

In the pl_custom_rewrite_rules() function, change the REGEX pattern to ^new_slug/(.*)$ as in: add_rewrite_rule( ‘^new_slug/(.*)$’, ‘index.php?name=$matches[1]’, ‘top’ ); because WordPress strips the preceeding / from the request path (WP::$request), so using the ^/new_slug never evaluates to true. Additionally, in the pl_custom_permalink() function, remove the global $post; line because the function already receiving the proper post data … Read more

Custom URL routes

All internal rewrite rules must point to index.php. This isn’t a theme file, it’s the main bootstrap file in the root of your WordPress install. So, your rule should look like: add_action( ‘init’, ‘wpse26388_rewrites_init’ ); function wpse26388_rewrites_init(){ add_rewrite_rule( ‘properties/([0-9]+)/?$’, ‘index.php?pagename=single-deal&property_id=$matches[1]’, ‘top’ ); } You can then assign the deal.php template to your single-deal page in … Read more

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