Questions tagged [query-variable]
The query-variable tag has no usage guidance.
114
questions
0
votes
1
answer
34
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 ...
0
votes
2
answers
115
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( $...
0
votes
0
answers
15
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 ...
0
votes
0
answers
19
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 ...
0
votes
0
answers
59
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 ...
0
votes
2
answers
16
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 ...
0
votes
1
answer
69
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: ...
1
vote
1
answer
4k
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
...
0
votes
1
answer
56
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/...
0
votes
1
answer
163
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 ...
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 ...
0
votes
1
answer
460
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: ...
0
votes
0
answers
194
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
...
0
votes
1
answer
357
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 ...
0
votes
1
answer
175
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-...
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 ...
0
votes
2
answers
644
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 = ...
0
votes
1
answer
611
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 ...
0
votes
1
answer
44
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 ...
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 ...
2
votes
1
answer
37
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, ...
2
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 ...
0
votes
1
answer
307
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', '...
1
vote
1
answer
3k
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 = (...
1
vote
1
answer
6k
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));
...
0
votes
1
answer
531
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....
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 ...
0
votes
1
answer
304
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 ...
0
votes
2
answers
333
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 <- ...
0
votes
1
answer
504
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
...
0
votes
1
answer
493
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 ...
0
votes
0
answers
43
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 ...
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 ...
1
vote
0
answers
204
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 ...
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 ...
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('...
3
votes
1
answer
879
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 ...
1
vote
0
answers
324
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 ...
4
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 ...
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
...
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 ...
0
votes
1
answer
119
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(
'...
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/([^/...
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 ...
0
votes
1
answer
344
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....
1
vote
0
answers
623
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 ...
0
votes
1
answer
266
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/
...
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 ...
0
votes
0
answers
266
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 ($...
0
votes
0
answers
423
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', '...