Questions tagged [variables]

A variable is a storage location and an associated symbolic name (an identifier) which contains some known or unknown quantity or information, a value. The variable name is the usual way to reference the stored value; this separation of name and content allows the name to be used independently of the exact information it represents.

75 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4
votes
0answers
1k views

Setting Cookie Using a Variable from the URL

I need to hand code an affiliate link (we do not want to use an existing plugin). I do not do a lot of coding, so bear with me. It seems so simple I have a link: http://www.domain.com/?code=8765 ...
2
votes
0answers
317 views

Setting HTML properties in a Gutenberg plugin using WordPress settings

I want to set the maxlength property on a TextControl I define in a Gutenberg plugin. This length is to be set from a setting in my WordPress plugin (the one that loads the Gutenberg plugin). I ...
2
votes
1answer
679 views

Replacing string with a variable in php

I have following code in my plugin of Wordpress: wp_localize_script('ffd_js_script', 'myAjax', array( 'ajaxurl' => admin_url('admin-ajax.php'), 'idinfo' => $...
1
vote
0answers
16 views

Remove add to cart icon/view product button woocommerce

I'm trying to remove a button that appears when hovering over the images on a woocommerce shop. (See images attached) The product is a variable product. Failing being able to do this I also tried to ...
1
vote
0answers
535 views

Woocommerce Create custom product type with variations

I have a plugin of booking that create a new product type of WC_Product. I'll like to change this booking product type for variable booking product type (new product type of WC_Product_Variation or ...
1
vote
0answers
56 views

Show only one variaton in catalog on meta key

Hello i have too much products with variations. I need display only one variations if enable. Catalog display data via taxonomy.php and basic loop. How i can show only one variations but in filter i ...
1
vote
1answer
764 views

MySQL variable in query

I've got tenant portal when I need to show running balance for each transaction. Here's query I've written which does what I need it to do. Problem I've got is that it doesn't work in Wordpress. Here'...
1
vote
0answers
36 views

Add comments for template variables

I am writing a small plugin that uses a custom template to render content. The plugin uses extract() to add variables that can be used inside the template. I was wondering if there is a standard for ...
1
vote
2answers
660 views

PHP, Creating a dynamic variable

Is there any way through which I can declare the dynamic variable in php. for eg, I am using a for loop and the variable name is $message. and I want to add some dynamic data at the end of the ...
1
vote
1answer
532 views

Excluding pages in WP_query using ACF

I have a custom loop for showing child pages of the current page, but I'd like to allow the WP user to enter page IDs to be excluded from the loop, using Advanced Custom Fields. My current loop is as ...
1
vote
1answer
774 views

How to put a variable in a instance in the widget

I am creating a widget that handles order numbers. The basic structure is as follow: // pretty generic widget functions public function widget($args, $instance) { $order_number = $instance['...
1
vote
0answers
466 views

Get custom post type's fields in a while loop as variables

I'm working on a page that shows the name of a lot of products (custom post type), and when the user clicks on the name he can see some product information. It's something like this: Main page with ...
0
votes
0answers
8 views

Product with variations doesn’t show variation image

We have a number of products with different variations (colors). Every variation has its own image in Woocommerce/Productpage. However, when selecting an other variation, no other image is displayed ...
0
votes
0answers
21 views

Best way to use variables in multiple functions?

So I am running into issues in Query Monitor - duplicate queries. The reason being that I have functions that need to get say, a customer's order status or the like. What is the cleanest, correct way ...
0
votes
0answers
34 views

WordPress wp-config custom variables

I know how to add custom variables to the wp-config.php file; however, they're not being picked up in my theme's functions.php file. When I echo non-custom variables, they show up. When I echo custom ...
0
votes
0answers
6 views

How to use $_GET via woocommerce_product_variation_get_price when Woo gets variations by AJAX?

I'm looking to manipulate a variation price using woocommerce_product_variation_get_price So on the product page when variation calculates the variation price by AJAX, if ?help=1 then the price will ...
0
votes
0answers
8 views

Passing browser infos to the wordpress function.php as a $_GET

I need to pass current/live browser information (like browser width) using javascript/jQuery to the wordpress function.php using the $_GET array/variable/filter/container method. Once the browser ...
0
votes
0answers
6 views

I need a variable for generating woocomerce coupon at checkout

I need a variable set-up for my customers to apply at checkout that will generate a unique different coupon code for different customer, and the coupon generated should expire in 48 hours after ...
0
votes
0answers
18 views

how to create a shortcode from a variable in plugin

im using WP User Frontend Pro plugin i want to echo the pack title using a shortcode to put it in bakery visual all what i know is this is the title $pack->post_title; i tried something like this ...
0
votes
0answers
52 views

Reduce Stock Based on Custom Variation Field Rather than Attribute (Working Script)

I currently have a script that works perfectly. The issue is, I want to use the value in a custom field I have created for my variations rather than an attribute. See code: // reduce stock based on '...
0
votes
0answers
17 views

Using a function / displaying the result of the function twice in same page

I have a script showing open/closing times. It is displaying fine when calling the function in my header file. When I try to call it in my mobile menu - CRASH - nothing or errors etc. (depending on ...
0
votes
0answers
20 views

What is better for passing variables to templates - include(locate_template.. or $wp_query->query_vars?

The answers here: Passing variables through locate_template are extremely helpful in solving the problem of passing variables to templates such as sidebar and footer. In short, which is best? ...
0
votes
0answers
44 views

Woocommerce; tax status for product variations?

I noticed that when creating a new variable product in Woocommerce and setting the tax status of the parent product to 'none', the variations still show: 'tax status: taxable' in the database. Does ...
0
votes
0answers
37 views

Get attributes for currently product

I have code: <?php $attributes = $product->get_variation_attributes($variation_ids); $attribute_keys = array_keys( $attributes ); ?> <?php foreach ( $attributes as $attribute_name => $...
0
votes
1answer
73 views

Getting value of variable from functions.php and debugging it

I am trying to inspect a variable obtained in functions.php for debugging purposes. I am defining a variable $current_user by executing the shortcode to obtain the current logged-in user. Then I am ...
0
votes
1answer
42 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 ...
0
votes
1answer
529 views

How to change the value of a variable using input field?

I have created a wordpress website. I want to extract each user's data using php through his/her id. I have created this code; <?php $userid = /* help me get the below input field's value */ $...
0
votes
1answer
157 views

Defining constant in a plugin to use in another plugin

I am wondering if this is possible or if there is another, better way, of doing things. Google-foo didn't help. So, I have two plugins, aa-frontend and aa-site. I need to define a constant or ...
0
votes
1answer
32 views

Pass post ID from archive template to functions file

I have an archive template where I am displaying a "featured post" at the top of the page. I am building my post loop for the rest of the page in the functions.php file. What I would like to do is get ...
0
votes
0answers
43 views

How to access custom class methods from any include without using global

I am trying to do the following functions.php class Test { public function hello(){ return 'Hello'; } } $test = new Test(); header.php or any other include echo $test->hello();...
0
votes
1answer
65 views

saving variables after redirect

Is there a way to save a variable after you redirect to another page. For example... I want to save the password submitted from my form into the variable $temp_passkey, and be able to access it on the ...
0
votes
0answers
35 views

Multiple values for one variable

I have a custom plugin that was written by someone, I can't reach anymore. It has a search option, that produces a table with seminars in different cities. Right now I can have a query with this ...
0
votes
1answer
1k views

Woocommerce image variation not changing

I have Design and size variations of a product and have uploaded the various images accordingly. On the front end, the images are swapping when the user selects different Design and size. The ...
0
votes
0answers
300 views

How to display variables from plugin?

I've been working on creating my first homebrew plugin for our site, and I'm so daggone proud of what I've been able to do so far. The plugin is called by a shortcode - in the plugin, I've ...
0
votes
0answers
358 views

fix undefined variable in native wp files

I had a trouble with installing new plugins as I would get error message "Something went wrong" when trying to search for any plugin. When I enabled wp_debug i got error saying Notice: Undefined ...
0
votes
1answer
161 views

How to make url variable?

I just want to know how can I make variables on my wordpress link? so can I make get function on my page. Example I have url page www.example.com?page=123 and add some variable like mobile number. ...
0
votes
1answer
447 views

Redirect users in first login to a dynamic link

I'm using a Gravity Forms user registration to handle registration processes, and I use Gravity Forms custom post type + wp resume manager to let the user submit some fields in his resume within the ...
0
votes
1answer
436 views

Passing parameter from the current URL to redirect to another url

I have a search results page and on the page, I would like to be able to filter by category. So when the user searches an item, it gets passed to the results page in the url like: website.com/?s=...
0
votes
0answers
159 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
1answer
414 views

Not getting input from get_query_var

I want to pass on values from a search field and use those values to show posts with specific tags. I'm using get_query_var for this. I'm almost there, but not getting the values in my query. When I ...
0
votes
1answer
5k views

How to insert current user ID in a shortcode?

I have a shortcode from a plug-in called Pods that is used like [pods-form name="user" id="" fields="my_field, my_field_2, my_field_3"] Parameter name contains the name of the custom post type (...
0
votes
1answer
38 views

Add array of category IDs to global variable?

I'm wondering how I can add a global variable containing an array of category IDs. On my site, I have menus and custom loops and every time I want to delete a category of them, I have to access each ...
0
votes
1answer
141 views

Use a select box to change a php variable

I am currently stuck on a little problem. I'm using a localStored value to differentiate the content that user sees depending on their choice. <div class="form-group form-inline hidden-print"> ...
0
votes
0answers
126 views

Where can I find the declaration of `$_wp_theme_features`?

Where can I find the declaration of the global array $_wp_theme_features on WordPress core?
0
votes
1answer
121 views

Child theme functions.php file change database entries

I'm sure my title is not the correct terminology. I will do my best to explain what I'm trying to accomplish. Years ago I spent countless hours customizing a theme. I was finally forced to update ...
0
votes
1answer
31 views

require happens out of order

I have a page template that is including another file via require_once. I want this included file to have access to the $post object but it can't find it. So I ran something like this to see what's ...
0
votes
0answers
34 views

Can't access a variable defined in another template despite using GLOBAL

I created, populated and successfully echoed a variable x in header.php. Then in my front page template I did global $x then echo $x. This displays nothing. Why?
0
votes
1answer
40 views

How to get variable from function.php to loop file

i had code in function.php file : $selective = new WP_Query($args_selective); get_template_part( $loopFile ); i cant get $seletive in my loop file. Help me pls. Thanks for any answer !
0
votes
0answers
73 views

Custom Taxonomy Link Text Echo Name Not Slug

I'm a little lost about where I can place a simple php echo within a loop. I have a "program" taxonomy where each program is echoed onto buttons. Right now I'm only echoing the slugs for the link ...
0
votes
0answers
713 views

Setting a cookie in functions.php and it gets deleted when working on an other function

My first function gets the parameters from the URL and sets the cookies: /** Get variables from the URL and set them into the coockie **/ add_action( 'init', 'set_utm_cookie'); function ...