Questions tagged [query-variable]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
22 views

Wordpress add a rewrite rule to a page to accept a GET variable

I want to rewrite mysite.com/events/submission/test-event-01 to mysite.com/events/submission?epl=test-event-01 This is what I have done so far without any result. I get a 404 error (mysite.com/events/...
user avatar
  • 213
0 votes
0 answers
21 views

Creating an alternate path for a page

I would like to load the same page under a different URL, but not via a redirect. For example, suppose I create some page with id=6 - I can access this page via example.com/index.php?page_id=6 - if Im ...
user avatar
  • 21
0 votes
0 answers
37 views

Query vars to return the homepage

I would like to rewrite a path like example.com/foo to the "front" page (example.com). So when I request example.com/foo the content shown should be that of example.com. Note, a redirect is ...
user avatar
  • 21
0 votes
1 answer
18 views

How to allow WordPress to recognize a custom URL segment after a product URL and use a custom template?

Essentially I'm trying to allow a URL like this: https://example.com/products/my-product/test I'm using WooCommerce, my product base is /products, and the product name would be My Product here. I want ...
user avatar
2 votes
1 answer
328 views

Passing array of strings to a SQL statement in a WordPress plugin

I have an issue with passing an array of strings to a SQL statement in a WordPress plugin, because the prepare method adds a backslash before each apostrophe. // I have an array of strings. $the_array ...
user avatar
0 votes
0 answers
33 views

Custom post type - disabling query_var gets 404?

I don't want my custom post type to be loaded by using query string at ?{query_var}={post_slug}. So I have set the argument below in my custom post type: 'query_var' => false, But this gives me a ...
user avatar
  • 324
0 votes
1 answer
199 views

Query_vars support in Rest API

I am trying to make query_vars work in rest api. In my code bellow if I call wp-json/wp/v2/cpt?city=test, my debug output always returns an empty string. <?php /** * Plugin Name: Test * Author: ...
user avatar
  • 212
0 votes
0 answers
28 views

Wordpress keeps removing query var from the URL

I have a custom post type "press-release" that I pass a query var to the template through the URL. The URL structure looks like this. MYDOMAIN.COM/press-release/TITLE-OF-RELEASE/?client=123 ...
user avatar
  • 173
0 votes
1 answer
103 views

How to pass a variable to get_template_part that's updated every time the template part is called?

I have a loop and in that loop I use a get_template_part to call the HTMl for the post to display. I also have a variable (number) to which +1 is added every time the loop runs. In this way I can ...
user avatar
0 votes
1 answer
91 views

Rewrite Rule for Post Meta

I would like to create an endpoint for a custom field. For example, I already have a custom 'competition' post type for which rewriting is working great and resolving at website.com/competitions/my-...
user avatar
0 votes
1 answer
15 views

Need help with regex

I have this definiton to add a query var: add_filter( 'query_vars', 'add_reg_query_vars', 10, 1 ); function add_reg_query_vars($vars) { $vars[] = 'seminar'; // return $vars; } and this ...
user avatar
0 votes
1 answer
225 views

Query arg not available on init

I'm adding my query arg as such: add_filter( 'query_vars', function( $qvars ) { $qvars[] = 'my_query_var'; return $qvars; }); And when I do: add_action( 'init', function() { $string = ...
user avatar
0 votes
1 answer
371 views

Custom query_var to get URL paramater not working

I have a custom Wordpress login and if the user gets to the homepage and is not logged in, they are redirected to the custom login form(I have disabled this for now while I test). What I would like to ...
user avatar
  • 363
0 votes
1 answer
37 views

How can I get custom post types to recognize pretty permalink variables?

I'm using PODS to create a custom post type called "automobile" on my site. This results in a permalink structure that looks like this: /automobile/automobile-page I want to be able to send ...
user avatar
  • 1
0 votes
1 answer
48 views

Theme customisation - how to store javascript externally when it utilises php variables?

EDIT: Complete re-write I have been developing a custom extension for my theme over the last few weeks. This is my first time "developing" with Wordpress. All works fine and I am happy with the ...
user avatar
2 votes
1 answer
23 views

Taxonomy page template changing when using query variables

I'm hoping someone can help me fill in the gaps in my understanding of page templates and query vars: I've registered a custom taxonomy 'stream', and have set up a page template for that taxonomy, ...
user avatar
2 votes
1 answer
3k views

WordPress query through Products variation stock [closed]

I have WooCommerce variable products and a filter which is filtering products based on variation attributes. I have variation attribute depth which has numeric value (from 1 to 20) and the filter is ...
user avatar
  • 469
0 votes
1 answer
270 views

Integer based rewrite isn't recognized for value of 1

I have a simple rewrite to pass a variable: // Add custom URL parameters function add_custom_query_var( $vars ){ $vars[] = "item_id"; return $vars; } add_filter( 'query_vars', '...
user avatar
  • 149
1 vote
1 answer
2k views

Changing WP_Query params with url Query Var

:) I've used WP_Query to display there posts (travels) here http://boost19.delavec.si/wordpressP/produkti/ So... I've got this WP_Query that is looping through my custom posts <?php $paged = (...
user avatar
0 votes
1 answer
5k views

How to unset a set query variable?

My theme file, multiple times over, passes sets a variable to a template part used in a subsequent template part file via set_query_var, like so... set_query_var('feature_id', array(143866)); ...
user avatar
0 votes
1 answer
341 views

Rewrite query var on postname

I'm trying to do a rewrite, so that the query var is going to look pretty: This is the URL structure I got now: example.com/post-type-archive/post-name/?subpage=about This is what I want: example....
user avatar
  • 3
0 votes
1 answer
30 views

Custom permalink question

I have a multisite environment where I am switching databases to retrieve data in a custom post type entered on one site to show on the other site. On the site where the data is not stored (and the ...
user avatar
0 votes
1 answer
214 views

Why does a header location on admin_head remove the query var I'm setting in the location?

I have the following code which I thought would load the location with a query var of saved=1. public function __construct() { add_action( 'admin_head', array( $this, 'test' ) ); } public ...
user avatar
0 votes
2 answers
205 views

Wordpress pass url to page template when page does not exist

I created a page template to serve information dynamically. For url like example.com/the-hamptons => index.php?page_id=92&filter=the-hamptons For url like example.com/page-that-exists <- ...
user avatar
  • 183
0 votes
1 answer
333 views

How to include a query_vars value in document_title_parts?

I have a page template, used on a single page, which takes URL string parameters like this... http://www.example.com/mypage?tags=Publishing Facilitated like this... // Inherit the meta target ...
user avatar
0 votes
1 answer
254 views

How to call code when adding WooCommerce menu items via woocommerce_account_menu_items

I'm inserting menu items similar to the code example at https://wordpress.stackexchange.com/a/277080/137417, but I haven't encountered endpoints before and the documentation and tutorial I've looked ...
user avatar
0 votes
0 answers
40 views

use query var argument as verification link?

In a from response email I want to send a link to with a unique url string attached to it. Clicking that link and visiting the website through that link should trigger a function. The way I thought to ...
user avatar
0 votes
1 answer
49 views

Trying to Create a PHP Variable for post_type that can be referenced Site Wide

I have several sites with several custom PHP widget loops I've created. I would like to reuse these widgets in other areas and site, but with different custom post types. The only unique thing in ...
user avatar
1 vote
0 answers
127 views

Redirect Uploads Folder to Query Vars in WordPress

I'm looking to redirect pdfs documents from the uploads folder to WordPress to prevent unauthorized site visitors from viewing them. I have used the code provided from this thread How to restrict ...
user avatar
  • 11
0 votes
0 answers
72 views

Custom Fields Query Vars and Rewrite not working

i have a problem with query vars and rewrite rules. I have - a page called "luoghi" - one custom field called "test_city" - a query var called "city" Into "luoghi" page i did the query with custom ...
user avatar
0 votes
1 answer
2k views

how to access query string in wordpress?

There are several ways I have seen this question worded, so I tried to make mine generic. Let's say I go to this page: example.com/page/?utm_source=test&s=test&page=12 get_query_var('...
user avatar
  • 151
3 votes
1 answer
733 views

Custom permalink with pagination

I have a custom post type called news and in order to distinguish current and old news posts I have a custom field where the client can mark a news post as 'archived'. So my permalink rewrite code ...
user avatar
1 vote
0 answers
269 views

Custom taxonomy rewrite with query var returns %2F in URL

I'm facing a (hopefully) small issue right now I can't seem to solve. First of all my page is set up in a way that all my projects (custom post type) are displayed on one big page with a query var ...
user avatar
3 votes
2 answers
4k views

Enqueue Script with URL parameters

I have the following I'm trying to enqueue in functions.php wp_enqueue_script( 'param-example', 'https://domain.com/example?f=j&s=w&c=t', array(), null ); Except WordPress is escaping the ...
user avatar
0 votes
0 answers
40 views

CPT year wise archive based on custom date Field

I am trying to group( archive ) my CPT (fcra_donation : has_archive => true) based on a custom date Field ( sukritham-donation-date : format yyyymmdd (20160506). Here is my code in my functions.php ...
user avatar
  • 201
5 votes
1 answer
7k views

paginate_links ignore my format

I need the pagination liks to have the url, like: current_url?p-page=1 current_url?p-page=2 current_url?p-page=3 And so.. The reason I need this is because I have other params in the page. the ...
user avatar
0 votes
1 answer
64 views

Get list of all Topics in use by a custom post type

I have a custom post type that has an option to tag that post as part of a 'Topic'. This is set in the taxonomy: register_taxonomy( 'topic', array('post','blog','shows'), array( '...
user avatar
  • 113
1 vote
1 answer
1k views

how to add rewrite rule to wordpress default post type

hello trying to add rewrite rule to default post type with this add_action('init', 'add_my_rewrite'); function add_my_rewrite() { global $wp_rewrite; $wp_rewrite->add_rule('(.*)/server/([^/...
user avatar
1 vote
0 answers
2k views

add_filter('query_vars') not working in custom template

I'm trying to add a query parameter to a custom template in order to look up a record from the DB with the ID passed in. Here's how I'm attempting to do it: At the very top of my custom template, I ...
user avatar
0 votes
1 answer
285 views

Prevent WordPress to remove query vars from url

I have a website and in my localhost I can access page pagination through query_vars. However, when I upload this site to my server, it does not recognize query_vars and simply removes it from the URL....
user avatar
  • 101
1 vote
0 answers
468 views

Get query parameters from external url and make a redirection

assuming that I have been redirected from an external API, to my front page website, and in the current url there is some query parameter provided by that API, how can I get those parameters and make ...
user avatar
  • 25
0 votes
1 answer
239 views

Force Rewrite Query Var On Hierarchical (Nested) Page

I want to use a hierarchical (nested) page with a query var to pull dynamic content. I had things working when the page wasn't a child of another page, such as: mysite.com/my-page/1234-my-var/ ...
user avatar
  • 349
4 votes
1 answer
1k views

Filtered query_vars becomes global. Why does this work?

For some reason that's not quite clear, when I add custom query_vars, they become available everywhere without the need of an accessor like global or get_query_var() // if your url contains the var ...
user avatar
0 votes
0 answers
227 views

WP CLI - Pass Query / URL Variable to Cron?

Is there a way to pass URL / Query variables when you run: wp cron event run using WP CLI? I have a specific event and ID I want to pass to it but don't know if it is possible or how to pass GET ($...
user avatar
  • 101
0 votes
0 answers
318 views

Own query vars are not displayed

I'm trying to write a custom rewrite rule and then to a redirect based on the last part of it: add_filter('query_vars', 'a_add_query_vars'); add_action('init', 'a_rewrite_tags'); add_action('init', '...
user avatar
  • 101
3 votes
3 answers
6k views

How to add query parameters to all internal links?

I'm trying to add url query parameters to all internal links inside a WordPress blog. For example, client lands on the blog with this link: www.example.com/?p1=test&p2=test I want the links ...
user avatar
  • 53
1 vote
0 answers
1k views

set_query_var doesn't seem to work on init hook

Based on the trick of using set_query_var with get_template_part to easily pass variables from one template file to another (see here: Method 3), I thought I could use the same method for passing ...
user avatar
  • 431
1 vote
1 answer
777 views

get_query_var returns wrong default value

I want to make my custom terms to be sortable by users. I've created different links to let the user decide how they want to sort it. <a href="?orderby=name&order=asc" data-target="#">Name ...
user avatar
  • 179
3 votes
2 answers
6k views

add_rewrite_rule not working for page var

I have a page called mypage and a custom query var called mycustomvar, I am trying to rewrite the following url: http://example.com/index.php?name=mypage&mycustomvar=someword to http://example....
user avatar
  • 883
0 votes
1 answer
35 views

Taxonomy Rewrite Problem

I have actor and genre taxonomies. add_action('init','ap_url_redirect_rules'); add_filter('query_vars', 'ap_register_query_vars'); function ap_url_redirect_rules(){ add_rewrite_rule('([^/]+)?$', ...
user avatar
  • 57