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.

Filter by
Sorted by
Tagged with
0
votes
1answer
2k views

WooCommerce quantity box for each variation

I'm trying to display a quantity box next to each of my product variations in the main shop page. I have t-shirts listed in different colors and sizes and sell B2B. I therefore need the quantity ...
-1
votes
1answer
53 views

Use a Variable in update_post_meta as the $meta_key

looking at the example on wordpress.org update_post_meta( $post_id, $meta_key, $meta_value, $prev_value ); I seem to be having a problem replacing $meta_key with a variable. here is my code ...
1
vote
1answer
554 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['...
0
votes
1answer
46 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
0answers
48 views

Send Front End PM Message after Succesful Ultimate Member Registration

We're working on a Wordpress project which requires: - a list of Therapists with a "Contact" button for each (done, listed with Store Locator and an Ultimate Member user group for the Therapists) - ...
0
votes
0answers
24 views

Pass Underscore.js Variable to a Shortcode

I am using WP Store Locator to list nearby "Therapists" (therapists=custom user group with Ultimate Member, this part of the project works perfectly) and Front End Pm for a basic messaging ...
1
vote
2answers
529 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 ...
0
votes
3answers
534 views

Passing variable from child theme function to parent theme filter

I want to pass a variable from my child theme function to a filter which resides in my parent theme. Please let me know whether below code will work or not ? Is it the right way ? Code in Parent ...
0
votes
1answer
30 views

Passing function into add_action always returns the first argument

I'm building a plugin that iterates across and parses the arguments of various WordPress hooks, and because of the flexibility needed I'm passing a function as the callable parameter in add_action: ...
4
votes
2answers
3k views

What is the best way to store custom variables

I need to store the id and secret key of my FB application. I don't want to write them directly in my template. What do you recommend ?
0
votes
1answer
25 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
505 views

Adding to an array & passing it through do_action/apply_filters

For exercise I am working through a PHP class to add meta boxes I found on GitHub. I just copied the code and now I am playing around with it to understand it. It works like this: The file ...
0
votes
0answers
10 views

Passing a variable in a customer url menu

I'm trying to add a link to my menu that leads to the following page: /ar/variable where the variable is the page the user is currently visiting for example: when the user is on page site.com/contact ...
0
votes
1answer
4k 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
20 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
40 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
397 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
459 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'...
0
votes
1answer
586 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
1answer
433 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' => $...
0
votes
1answer
17 views

Turning variable into a value set in shortcode

I have a site on WordPress, and first of all I have this PHP shortcode that helps me to make customizable links in WP post editor without turning my CSS files into a dump of classes with basically the ...
0
votes
1answer
96 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)); ...
1
vote
1answer
69 views

Using a variable in is_page(array())

Similarly to this topic I need to extract some page IDs from user input (a theme options admin page), store them in a variable, and then filter using the is_page() filter. The input consists of ...
0
votes
1answer
12 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
22 views

Create new meta field with existing field data on publish

I am using a frontend publish plugin that uses Wordpress's default publishing hooks to publish, and I am trying to create a function that will grab the data of one of the fields in the frontend form, ...
0
votes
0answers
28 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 ...
6
votes
5answers
7k views

Where to get information about array fields in $_REQUEST?

I just started to learn PHP and doing things with WordPress and I am a bit confused about information in Codex. Was told that Codex got all info I required but I got stuck with it. What array fields ...
0
votes
1answer
21 views

Post URL based on Custom Post Types variables

I would like to create custom post URL from Custom Post Types variable. I considered a way to do that: In Permalinks settings, I see there are some default tags you can choose to compound URL from (%...
52
votes
9answers
60k views

Passing a variable to get_template_part

The WP Codex says to do this: // You wish to make $my_var available to the template part at `content-part.php` set_query_var( 'my_var', $my_var ); get_template_part( 'content', 'part' ); But how do ...
-1
votes
1answer
26 views

How to filter part of a variable if it is no array?

I was wondering if it is possible to filter out a part of a variable, if it is no array. Or can I only replace the whole code, or add code to it? Let's say I have this code: $output = '<...
0
votes
0answers
53 views

Force selected attribute variable of a product for all products in Woocommerce

If a custom chooses variable blue color of product, in all other products blue color variable should be forced (auto selected) If this possible how can I do it? Thank you
0
votes
1answer
30 views

html element to separate php variable strings - ACF datepicker

i am using ACF to display an internationalized date with this code : <?php $dateformatstring = "l j F Y"; $unixtimestamp = strtotime(get_field('date')); ?> <?php echo date_i18n($...
2
votes
0answers
149 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 ...
1
vote
1answer
37 views

Plugin. Html code in Template

perhaps i am blind or something but i searched alot, here and also wordpress codex and similar. In example i wrote a plugin that reads something from database and print someting. But how can i archive ...
1
vote
2answers
898 views

How to get variables from fucntion.php to my plugin files

I have written a function in functions.php that gets variables from a contact form and sends the inputs (and some other info like IP and location..) to my email. I am starting to work on my first ...
0
votes
1answer
236 views

How to find php variable of wordpress theme settings

I'm new to PHP and WordPress, but I have some experience with python, for my site I use the traveller theme. How can I find the exchange rate variable that exists in theme settings (the red square on ...
0
votes
0answers
519 views

set_price in woocommerce_before_calculate_totals not working

I am trying to update the price of the product based on user input on the product page. add_action( 'woocommerce_before_calculate_totals', 'extra_price_add_custom_price', 9999, 1 ); function ...
1
vote
0answers
30 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 ...
0
votes
1answer
107 views

How Do I Find & Remove H1 From Site-Title-Wrapper? [closed]

Good Afternoon, I am having difficulty removing a duplicate H1 tag, which is located in my Site-Title-Wrapper, per source code. When I access "Edit Theme" and load the "site-title.php" I can see the ...
0
votes
0answers
19 views

How to get list of (all) predefined variables?

Is there a list of all the WordPress predefined variables? Like, for example, this php manual page. I could not find it in the new WordPress Code Reference, while in the "old" Codex the page seems to ...
0
votes
1answer
2k views

Rewrite Rules problem when rule includes homepage slug

I have page Example (ID=443, slug=example) that is configured, through Dashboard->Settings->Reading, as the home page of my WP site. I also have the following rewrite rule configured: [(example)...
0
votes
3answers
21k views

Use conditional logic for woocommerce variable product

I have been developing a woocommerce store. Now I have a requirement from client which I can't figure out how to do... The problem is we can use variable product in woocommerce, it's simple but what ...
0
votes
1answer
175 views

Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]

I followed this quick/well laid out wordpress tutorial for adding custom fields to WooCommerce variations. http://www.remicorson.com/woocommerce-custom-fields-for-variations/ Everything worked great....
0
votes
0answers
44 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
1answer
30 views

Add audio file to post using custom term meta field as link [closed]

I am trying to add an audio file to my custom post type using a custom term meta field as a link, but I can't get it right. Here is how I would normally display a custom term meta field: <?php $...
5
votes
1answer
7k views

How to Use Wildcards in $wpdb Queries Using $wpdb->get_results & $wpdb->prepare?

I am attempting to make a custom search for BuddyPress groups. Here is my method: public function search_groups($string){ global $wpdb; $results = $wpdb->get_results($wpdb->prepare( ...
0
votes
0answers
212 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 ...
1
vote
0answers
360 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 ...
0
votes
1answer
37 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
votes
1answer
19 views

PHP Use Declared array Variable inside already Declared Array

i have created one class in which i declared public associative array. class test{ public $basicCols= array( array('title'=>'KEY', 'field'=>'slug','options'=>$optList), array('...