Custom Fields Query Vars and Rewrite not working
Custom Fields Query Vars and Rewrite not working
Custom Fields Query Vars and Rewrite not working
If your query var tags is registered properly then the following code snippet will definitely work, I’ve tested it. It’s a modified version of your code snippet. Please make sure to add the code to your functions.php file. function prefix_custom_title($title_parts) { global $wp_query; if (isset($wp_query->query_vars[‘tags’])) { $title_parts[‘title’] = $wp_query->query_vars[‘tags’]; } return $title_parts; } add_filter( ‘document_title_parts’, … Read more
You are getting a ‘page not found’ because it is exactly that, not found. What you can do is create a page, for instance, called ‘locations’ then set it up like this example.com/locations/the-hamptons => index.php?page_id=[id_of_locations]&filter=the-hamptons
If you want to perform any redirects, you have to send your header before site sends any output. admin_head is an action that allows you to print your custom code inside <head> tag of admin sites. But if it’s inside of <head>, then some output is already sent to the browser, so you can’t perform … Read more
What you need is to register your own Rewrite Rule. To do it you should use add_rewrite_rule function. function my_custom_external_rewrite_rule() { add_rewrite_rule(‘^post-type-name/([^/]+)/?’, ‘index.php?page_id=<PAGE_ID>&external_page_name=$matches[1]’, ‘top’); } add_action( ‘init’, ‘my_custom_external_rewrite_rule’ ); And you’ll have to register your custom query variable (using query_vars hook): function my_custom_external_query_var( $query_vars ) { $query_vars[] = ‘external_page_name’; return $query_vars; } add_filter( ‘query_vars’, ‘my_custom_external_query_var’ … Read more
So, first up, I don’t believe that you need a rewrite tag in this situation, so you can omit that. The issue, I believe, with the remaining code is that your rewrite rule is only capturing 1 match (because there’s only one set of ()), so subpage isn’t receiving a value. Additionally, your rule seems … Read more
Since it’s a plugin, you should enqueue jQuery first. Inside your add_action(‘wp_head’, function () { before wp_register_script( ‘custom_script’, get_stylesheet_directory_uri() . ‘/custom.js’ ); add : if ( ! wp_script_is( ‘jquery’, ‘enqueued’ )) { //Enqueue jQuery wp_enqueue_script( ‘jquery’ ); } This will check if jQuery is loaded and if not it will load it. Then, in your … Read more
Building Custom URLs in WordPress discusses how to use Pretty Permalinks to display posts using additional parameters. Jump to the section on Custom Query Vars. That’s where your situation begins to be addressed directly. In particular, you may want to use the example using ‘pre_get_posts‘ to retrieve parameters and adjust the WP_Query using a meta_query, … Read more
The get_query_var() function and/or method only works with registered WordPress query_vars. You can actually view the method via get_query_var(). The normal URL parameters you can access with the normal PHP super global $_GET.
WordPress keeps removing query var from the URL