Pass PHP through redirect and custom fields

Without touching rewrites – you could probably do somthing like website.com/?goto-amazon=<?php echo get_the_ID() ?> Which’ed output website.com/?goto-amazon=42 Where 42 is an example of a post that contains the amazon_keywords. In your site you could listen for the goto-amazon query and redirect thereafter add_action( ‘init’, function(){ if (isset($_GET[‘goto-amazon’])) { $keywds = get_field(‘amazon_keywords’,intval($_GET[‘goto-amazon’])); $link = “http://www.amazon.co.uk/s/?_encoding=UTF8&camp=1634&creative=19450&field-keywords={$keywds}&linkCode=ur2&tag=AFFID”; wp_redirect($link); … Read more

htaccess redirect throws an error: PHP Catchable fatal error: Object of class WP_Error could not be converted to string

They aren’t really connected. It’s just a redirect after all. The error means that some code in your website wrongly passes a WP_Error object to wp_kses_no_null(). In your position I’d put something like this into this function for debugging: if ( is_wp_error( $string ) ) { var_dump( $string ); debug_print_backtrace(); } This way you can … Read more

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