How to create custom search result page with custom URL parameters for custom post type?

Add this code in functions.php function custom_rewrite_rule() { //Initializing Rewrite Tags add_rewrite_tag(‘%begin-date%’, ‘([^&]+)’); add_rewrite_tag(‘%end-date%’, ‘([^&]+)’); add_rewrite_tag(‘%offset%’, ‘([^&]+)’); //Find page rewrite rules add_rewrite_rule(‘^find/([^/]*)/([^/]*)/([^/]*)/?’,’index.php?page_id=<SEARCH_PAGE_ID>&begin-date=$matches[1]&end-date=$matches[2]&offset=$matches[3]’,’top’); add_rewrite_rule(‘^find/([^/]*)/([^/]*)/?’,’index.php?page_id=<SEARCH_PAGE_ID>&begin-date=$matches[1]&end-date=$matches[2]’,’top’); flush_rewrite_rules(); } add_action(‘init’, ‘custom_rewrite_rule’, 10, 0); On your custom search page template $begin_date = get_query_var(‘begin-date’); $end_date = get_query_var(‘end-date’); $offset = get_query_var(‘offset’) ? get_query_var(‘offset’) : 1; Create a page having slug find and … 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

$_GET parametters not working in an specific template

WordPress is removing all unknown (not registered) $_GET parameters while processing the request (same is true for $_POST). You can either register the custom variable, or just go the canonical PHP way by using filter_input(). This will access the original, unchanged GET parameters. If you are using filter_input(), you have to hook into pre_get_posts to … Read more

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.

Two sets of url one content?

You can create custom post type to manage your secondary content (multilanguage i suppose) and set these /fr/ your CPT rewrite base. Create a CPT function add this to your function. $rewrite = array( ‘slug’ => ‘fr’, ‘with_front’ => false, ‘pages’ => true, ‘feeds’ => true, ); After that set CPT rewrite option to rewrite … Read more

Redirecting “wrong” but working links to their canonical URL in order to prevent search engine penalties (e.g. /123/ at the end of URLs)

Ensure that you provide a canonical url – this should ensure that search engines don’t see the url variants as duplicate content. Additionally, appending a number on the url, will make WordPress try to access that page. Using a debug plugin, such as Debug Bar, is quite useful for diagnosing this kind of behaviour as … Read more

Show Mysql table elements as pages in WordPress

To do that, create custom post type to store info. You do not need to create any custom table as your every record will be saved as a unique post in your custom post type. For detailed assistance, please have a look at the documentation here: https://codex.wordpress.org/Function_Reference/register_post_type Let us know if there is any confusion. … Read more