Questions tagged [query-variable]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
12 views

How does WordPress manage to differentiate between post and page URLs without a distinct base, and how can I replicate this functionality?

I want clean URLs without a custom taxonomy name or custom post name. The project and its structure are somewhat complex. The customer wants certain strings from a third party plugin to be removed ...
Rick Pestel's user avatar
0 votes
1 answer
12 views

`query_var` values empty in theme file after `add_rewrite_rule` redirection

I am redirecting a specific url format using add_rewrite_rule after adding an additional query_var (mlang) to it. Example: http://localhost/periodicals/sri-bn is to be redirected to http://localhost/...
sariDon's user avatar
  • 265
0 votes
2 answers
131 views

Unable to Retrieve Query Parameters Passed in URL

I would like to get the query parameters passed via the URL on a WordPress site. Very easy, I've never had a problem before. According to the address bar and dev tools my request URL is: https://...
Mitchell Bennett's user avatar
0 votes
1 answer
90 views

Passing queries in the Homepage loads index.php instead of front-page.php

The site that I'm working on uses a custom theme built by me. My Homepage is a static page, which uses the file front-page.php. My index.php is only used for "blog type" of pages. I want ...
Julia's user avatar
  • 3
0 votes
2 answers
284 views

Why does $_GET return values but get_query_var does not?

I have a bunch of query parameters that have been added with add_filter( 'query_vars'. I'm subsequently querying these with get_query_var like so: $search = '' !== sanitize_text_field( get_query_var( $...
Motivated's user avatar
  • 205
0 votes
0 answers
20 views

passing vars to pages in wordpress 6 and search them

I've got a number of challenges I'm trying to work through in WordPress 6. I have 100s of items in a separate database I want to display on one page in WordPress. For example, I have a list of birds ...
Ted Baxter's user avatar
0 votes
0 answers
22 views

How do I defeat the default action of a query variable on home page redirects to posts page

I am using a query variable to pass some information around the site. It works fine, except that Wordpress is operating some rewrite in the background. In particular, on the (static) home page adding ...
Chris Pink's user avatar
0 votes
0 answers
93 views

Pagination with Query String instead of Path

Is it possible to use ?page=2 instead of /page/2 for pagination? When I try and navigate to a url containing ?page=2 the query string is removed from the url before the page loads and although I ...
Cam Parry's user avatar
0 votes
2 answers
23 views

Send a variable with a URL and get a variable with Wp query

I want to send a variable with a url and get the value and insert that value to a variable. <a href="domain/newsletter-by-year?year=2020">GO TO THE NEWSLETTER FROM 2020</a> ang ...
kelvin ramirez's user avatar
0 votes
1 answer
101 views

query_vars doesn't return query string (trying to get data from $wpdb)

I have a ref query string which matches rows in my wp_invites table. In my wp_invites table, I have the following columns: lead_name reference Let's assume here is one of the rows: Lead name: ...
Freddy's user avatar
  • 147
1 vote
1 answer
5k views

$_GET vs get_query_var()

Is there is any advantage of using the get_query_var() over $_GET()? I have tried like this myurl?posts_per_page=2 and the results are totally different echo $_GET['posts_per_page'] // output is 2 ...
user avatar
0 votes
1 answer
58 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/...
sariDon's user avatar
  • 265
0 votes
1 answer
187 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 ...
Timothy Fisher's user avatar
2 votes
1 answer
1k 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 ...
Ramona Morea's user avatar
0 votes
1 answer
516 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: ...
Laurent's user avatar
  • 214
0 votes
0 answers
255 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 ...
Jason's user avatar
  • 205
0 votes
1 answer
384 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 ...
ralphjsmit's user avatar
0 votes
1 answer
192 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-...
Kevin Nugent's user avatar
0 votes
1 answer
20 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 ...
Joe Lipps's user avatar
0 votes
2 answers
715 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 = ...
Daniel M's user avatar
0 votes
1 answer
626 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 ...
user13286's user avatar
  • 255
0 votes
1 answer
45 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 ...
Bill's user avatar
  • 1
0 votes
1 answer
51 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 ...
Shaun21uk's user avatar
2 votes
1 answer
51 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, ...
alanbrown-ca's user avatar
3 votes
1 answer
4k 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 ...
wplearner's user avatar
  • 489
0 votes
1 answer
310 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', '...
Kermit's user avatar
  • 146
1 vote
1 answer
4k 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 = (...
Pr0metheus's user avatar
1 vote
1 answer
7k 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)); ...
Robert Andrews's user avatar
0 votes
1 answer
567 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....
Jesper's user avatar
  • 3
0 votes
1 answer
33 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 ...
Barry Tuber's user avatar
0 votes
1 answer
312 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 ...
bigdaveygeorge's user avatar
0 votes
2 answers
375 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 <- ...
jdias's user avatar
  • 183
0 votes
1 answer
548 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 ...
Robert Andrews's user avatar
0 votes
1 answer
530 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 ...
Andre Clements's user avatar
0 votes
0 answers
44 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 ...
lowtechsun's user avatar
0 votes
1 answer
53 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 ...
Katie R.'s user avatar
1 vote
0 answers
215 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 ...
hubble's user avatar
  • 11
0 votes
0 answers
73 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 ...
Davide De Maestri's user avatar
0 votes
1 answer
3k 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('...
adam rowe's user avatar
  • 161
3 votes
1 answer
894 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 ...
juliusbangert's user avatar
1 vote
0 answers
336 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 ...
felixwochnik's user avatar
4 votes
2 answers
5k 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 ...
Christian Norton's 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 ...
Anoop D's user avatar
  • 211
6 votes
1 answer
10k 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 ...
Toni Michel Caubet's user avatar
0 votes
1 answer
136 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( '...
tx291's user avatar
  • 113
1 vote
1 answer
2k 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/([^/...
Mouner Mostafa's user avatar
1 vote
0 answers
3k 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 ...
Alex Kibler's user avatar
0 votes
1 answer
351 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....
aleDsz's user avatar
  • 101
1 vote
0 answers
646 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 ...
Roberto's user avatar
  • 25
0 votes
1 answer
272 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/ ...
Ryan Dorn's user avatar
  • 349