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
39 views

Custom global variable not working in function

I've been stumped on this for a while and cannot for the life of me figure out why my function isn't able to reference my global variable. $query_obj = get_queried_object(); if ( is_a($query_obj, '...
0
votes
0answers
92 views

WooCommerce undefined variable “notices” for AJAX Add to Cart button

I'm currently developing a website with WooCommerce. I'm using AJAX for the "Add to cart" button on the Product page. In debug mode I have this message when a user add a product to his cart: ...
0
votes
1answer
20 views

Add text to variable

i am adding a option to a plugin. I want to add a Subfix after the curent test variable is return from a summarizer. So my data is in excerpt variable and i want to add text that is in this variable $...
0
votes
1answer
26 views

WordPress How do I pass a variable from one add_action to another?

I'm trying to add a custom field on the checkout form if a certain product category is in the basket and then on submission, check that field has been completed and add the result to the order details....
0
votes
1answer
54 views

keep a variable for all pages in memory from the url

I downloaded a referrer plugin and it works fine I create my custom link and everything is fine: https://testsite.com/?r=ty5x I have a conversion system that tells me how many users have come to my ...
0
votes
0answers
14 views

Dropdown for attribute

I have a product that only includes one attribute, so I can show it by default: add_action( 'woocommerce_before_add_to_cart_form', 'single_unique_variation_ui', 10 ); function ...
0
votes
1answer
16 views

Function that replaces the image in the absence of the post meta

i have thtis function in functions.php file function post_manage_columns($column_name, $id) { global $post; switch ($column_name) { case 'Average': echo get_post_meta( $...
2
votes
1answer
14 views

Adding variable for post title so post template can include auto-generated link to view on external website.com/{post title}

There's an external website that I'll be referencing within my posts that uses the same static format for their pages. Let's say it's website.com/view/1111, website.com/view/1112, etc. What I want to ...
0
votes
0answers
9 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
1answer
11 views

get variables data from functions.php to template wordpress (without global variables)

I have in wordpress functions.php file This sample works with one variable only, but i want multiple variables function variables() { $var1 = 'lorem'; return $var1; } in the front template ...
0
votes
0answers
23 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
1answer
42 views

Trying to add some custom text into Wordpress Post title via function.php

I need to add a custom text in wordpress Post title dynamically which I'm trying to add via this code in function.php Following code is not working add_filter('the_title', 'new_title', 10, 2); ...
0
votes
1answer
16 views

Echoing a variable comes out with lots of white space

I'm having trouble when I get variables from WP function come out very long. How do I trim that down? trim and substr do not see the spaces before or after. Why is it so long? <?php $...
0
votes
1answer
14 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 ...
2
votes
1answer
54 views

Cleanest/Fastest way to avoid calling and retrieving data from the database multiple times?

So this may be a very noob question, but I believe if I can get the answer to this I can clean up code and speed things up significantly. I build projects using Woocommerce quite a lot, and in doing ...
0
votes
0answers
102 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
10 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
1answer
24 views

What is the use of $content_width?

In the requirements of Envato I saw that they require a $content_width to be set. I searched for it on the internet but can't really understand why? I don't use it and the theme is responsive. If ...
0
votes
0answers
9 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
7 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 ...
1
vote
1answer
572 views

How to rewrite URL with PHP variables with htaccess to a normal looking URL?

I want to change an old database website that is not made in WordPress to WordPress. My site uses PHP variables so the URL is originally: example.com/index.php?tl=1&pg=2&bs=3&hcbs=4&...
0
votes
0answers
56 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 '...
1
vote
0answers
27 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 ...
0
votes
1answer
22 views

where is real values of variables?

I am working on editing the theme now for our center website, we are using Benevolence WordPress Theme. My question might look too obvious to most of you but I am new to word press and spending too ...
0
votes
2answers
56 views

Use one javascript variable into another javascript file

This is common.js jQuery(function ($) { var commonJs = { init: function () { }, showAlert: function () { }, } }); This is add.js jQuery(function ($) { ...
0
votes
0answers
19 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
2answers
51 views

Insert page content into another page with a changed variable

I'm trying to use this simple code to insert page (1) content into another page (2): <?php $id = 216; $p = get_page($id); echo apply_filters('the_content', $p->post_content); ?> So far so ...
0
votes
1answer
23 views

Local variable name in setup_postdata()

I am new in wordpress, I was using setup_postdata() method inside of a template file which was being called via shortcode function. I have not used global $post in my function. if ( ! function_exists(...
1
vote
1answer
167 views

Getting RGBA colour from gutenberg colourpicker

I'm working on a block that has it's own colour picker. This is working fine and I can see my background colour changing however I'm only able to get the hex value for the colour. I'm changing the ...
0
votes
0answers
42 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
1answer
21 views

Pass Variables or Variable Place-Holder from Editor to PHP

I'm building a method for my client to construct a message content to be sent with wp_mail. Within that I'd like them to be able to choose variables, for example the message might look like this in my ...
0
votes
0answers
63 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 ...
5
votes
2answers
4k views

Pass a PHP variable to another file

Is there a simple method to passing data from one file to another? I'm new to PHP and can't find a simple answer to my problem online. Apologies if this has been answered a million times & thanks ...
0
votes
1answer
520 views

How do I fix Undefined variable using $_POST in function?

I have the following function but with this error: Notice: Undefined variable: rating. hoa can I fix it? function save_comment_meta_rating($comment_id){ if(!empty($_POST['rating'])) $...
0
votes
1answer
394 views

Undefined variable error in new function

I wanted make function to count the time last the user read the article but after putting it in fuctions.php I see this error: Notice: Undefined variable: post in /home/karnetac/public_html/wp-...
0
votes
1answer
32 views

How to access or parse key/values that have “string”

Coming from a Perl background (no snickering) and trying to make sense of some new conventions. Not sure whether this is a PHP, WordPress, or Ninja forms question. $form_data //Ninja parlance ...
0
votes
1answer
88 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 ...
-1
votes
1answer
265 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 ...
0
votes
1answer
1k 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
145 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: ...
0
votes
1answer
219 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
33 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
46 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
252 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
2k 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
479 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
90 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 ...

1
2 3 4 5
8