Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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
1 answer
26 views

Passing a variable containing a comma separated list of values in a meta-query

My objective here is to collect a series of values from a custom repeater field into a comma separated list so they can be used in a meta query. The first part of this is operational, and I think ...
mtm's user avatar
  • 43
1 vote
1 answer
7 views

Get check box values inside array for use in posting form data

So I have the following function with an array of variables that handles a profile form. All but one is a typical input with the exception of 'member-comptency[]'. It's a select field field with ...
visyoual's user avatar
  • 111
0 votes
1 answer
38 views

How to make my scroll bar show under condition

I am using WP/code snippet with my wordpress website (here still on localhost) and I have a scroll bar that I want to show only when we add the text that will contain this scrollbar at the top. I have ...
Mehdi's user avatar
  • 103
0 votes
0 answers
17 views

How to access admin menu labels and links on front-end?

I am trying to retrieve a list of all the admin menu labels and links on the front-end so I can add them to my admin bar menu. I don't need the submenus. I was hoping to access global $menu, but it ...
Aristocles's user avatar
0 votes
1 answer
1k views

PHP Warning: Attempt to read property "id" on null

I'm receiving a php warning in the error when I run the below script in the footer.php file. The code works but is there is a way to write it better? <?php global $product; $mpn = ...
Ricardo Parsons's user avatar
0 votes
0 answers
57 views

Global variable not showing in shortcode

I am trying to show some variables when I hover over products image. For that I am using a shortcode to show the variable I need and the function do_shortcode(). However the needed variable is not ...
Mehdi's user avatar
  • 103
0 votes
1 answer
53 views

How to assign to each output values from foreach loop to a meta_key?

For a custom plugin with add start and end date of event/post, I must generate several datetime with the same meta key to compare the period of event with the period of weeks. I my case I'm obliged to ...
imagIne's user avatar
  • 83
0 votes
1 answer
17 views

WP_CONTENT_DIR and WP_CONTENT_URL in wp-config.php Someone can help me to understand?

define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/wp-content-assecure' ); define( 'WP_CONTENT_URL', 'https://'.$_SERVER['HTTP_HOST'].'/wp-content-assecure'); I moved a site to a new hosting ...
Paul's user avatar
  • 1
-1 votes
1 answer
38 views

Pass global variable data to localize_script

In my template file: product-list-section.php I loop through my products and add data to a global variable: global $product_filter_data; $product_filter_data = array(); // Loop products, grab ...
wharfdale's user avatar
  • 348
0 votes
1 answer
571 views

How to get default variation ID (woocommerce)

I need to create an additional "Add to Cart" button on the product page. In a simple product there is no problem with this. It is more difficult in a product with variants. To create such a ...
patryk siuta's user avatar
0 votes
1 answer
473 views

How can one use variables in a template or template part without polluting the global scope?

I'm a developer who is relatively new to developing in PHP for WordPress, and I am working on a WordPress site that has a considerable amount of custom code in the site's theme. I have been enjoying ...
NReilingh's user avatar
  • 103
0 votes
0 answers
58 views

How to set and retrieve cookies while in the loop

While inside the loop, I need to do some calculations with latitudes and longitudes to create a delivery fee based on a distance for each post. I have a couple hundred posts, but will only have about ...
Eric Wenger's user avatar
1 vote
1 answer
182 views

Dynamic header and footer template inclusion: footer script not included

I have a file that is being required by both the header and footer, and that file is meant to include the content for the footer or header dynamically. So in my header.php and footer php, I only set a ...
Galivan's user avatar
  • 243
0 votes
2 answers
43 views

Passing value from one hook to another

When someone logs into the wordpress dashboard I want the Pro version of my plugin to check for the latest version of itself on a remote (my) server. All it retrieves is the most recent version ...
Steve's user avatar
  • 297
1 vote
0 answers
27 views

WP query with variables gives no result for specific user

I'm trying to fetch one custom post with two values: the logged in user ID and a known string, both as variables. The query works out fine when testing on an admin account where the user ID is 1 and ...
Astra Martha's user avatar
1 vote
0 answers
1k views

WordPress is removing query variables like page, p from the URL of a custom static page

I am working on a custom template and displaying some posts (of custom type) teasers on it. In the template PHP file, I want to retrieve a URL query variable (if passed) and display the content ...
Imran Aslam's user avatar
1 vote
0 answers
288 views

Changing static text in a theme into variable content that also respects language. Easiest way

I bought a Theme which unfortunately has some static content, I managed to hide and remove some via editing and the custom css. But I have a text field above the navigation where it says "Work ...
Ozzy's user avatar
  • 11
0 votes
1 answer
29 views

Get access to variable from previous pageview, excluding ajax-calls

I want to generate a random string, and get it passed to the next pageview. I currently have the following code: add_action('init', 'set_global_pixelcapival'); function set_global_pixelcapival() { ...
superhenke's user avatar
1 vote
0 answers
41 views

Result of API Request to global variable?

I have an API Request for weather and the account of this weather stuff has a limitation of requests per minute. In my theme I have the weather information twice on the same page. So if I would make a ...
vriic's user avatar
  • 11
0 votes
1 answer
351 views

How to display emails as a post?

I am creating a Plugin that displays e-mails as posts. I used the following PHP to access those emails: <?php class Email_reader { // imap server connection public $conn; // inbox ...
Rohit kc's user avatar
0 votes
1 answer
1k views

How to send a php var to jQuery Ajax call with two different file

I need to send a private e-mail address from a php file (page.php) to an Ajax Call in an other jquery file (sender.js). This e-mail address must be invisible to user/or website until the user get an ...
imagIne's user avatar
  • 83
0 votes
0 answers
76 views

Unable to display multiple parameters from url by javascript through shortcodes

From our CRM I can generate URL's for customers that includes parameters. I want to use the information stored in this parameters to show dynamic content to the customers. Example: www.example.com/...
Ricardio's user avatar
5 votes
1 answer
430 views

Is there a way to extend WP_query so Custom Post Types can have properties?

Having trouble finding info on this. When working with lots of metadata/custom fields, I would really prefer to simplify getting the meta data inside of templates instead of using get_post_meta and ...
liquidRock's user avatar
1 vote
1 answer
58 views

Variable global scope [closed]

I'm trying to create a few custom post types, and instead of hard-coding their names I just want to define them as a globally scoped variable. I thought I understood the scope but apparently not. The ...
Fluxian's user avatar
  • 130
0 votes
0 answers
501 views

How to check a variable Changes

I have a variable $curr_price. Every time some user updates the variable, I want to show a message to the other users. Should I use a jQuery script something like this: $("curr_price")....
Roelf Keulder's user avatar
1 vote
0 answers
289 views

Is there a way to show Single Variation prices in the product loop when filters or attributes are active?

I have a WooCommerce store with variable products. Some products have 3 different attributes that are used for variations ie; Size, Comfort Level and Turning Cycle (as an example). I would like to ...
Jean Paul's user avatar
0 votes
2 answers
942 views

Change Page Title

I have successfully changed the name of a specific page using this code in my functions.php file: add_filter('pre_get_document_title', 'change_my_property_title'); function change_my_property_title($...
Joey Lawrence's user avatar
0 votes
1 answer
38 views

How to deal with too many $_POST variable conditions from ajax request at backend? [closed]

At work, we write a PHP application. I'm only a junior, but I'm dissatisfied with the problem of processing AJAX calls. Each of AJAX request is directed to the single appdata.php script. At appdata....
Sahasrar's user avatar
1 vote
0 answers
198 views

Pass variable from one function to another

I am trying to pass a URL and query string from one function to the other, as in the other function it captures the incorrect string, each time I try and pass it through to the second function it ...
KiriqN's user avatar
  • 11
1 vote
2 answers
3k views

Get value from shortcode to do something

For a project I want to use advanced shortcodes. Normally I define shortcodes within my PHP. This way it is always the information I have in my PHP-files that I show with my shortcodes (like [...
Ricardio's user avatar
1 vote
0 answers
234 views

Set and access global variable

I am learning plugin dev and modified this example snippet. I don't get why $myvar is empty in the my_plugin_action_handler function's scope. <?php /** * Plugin Name: TEST Plugin */ global $...
DerWaldie's user avatar
0 votes
1 answer
25 views

Custom column on CPT not showing correct value when meta data not set

Basically I have 2 custom columns in the 'edit.php' of my custom post type. What I need is when $item_type is set to 'page' but there is no page selected, 'No selection' is echoed (same for when '...
wp_dev99's user avatar
0 votes
2 answers
2k views

global $product is empty string when passed into function

I'm trying to optimize my functions.php file as I have a Woocommerce site with a bunch of customizations to the theme. Currently, my functions look like the following: add_action('wp_footer', '...
sackadelic's user avatar
0 votes
1 answer
781 views

Check if parent page has child page of certain slug

I currently have a function that checks to see if the page is a parent, and if so, do stuff. But I also want to check to see if the parent has a child page that has a certain slug. Basically, how ...
Garconis's user avatar
  • 144
0 votes
1 answer
248 views

Can't pass var from php wp_ajax into ajax script : result undefined or null

I can't understand why I get always a null or undefined response while trying to pass an php error from registration form into ajax script. I work in a custom plugin to add login, registration and ...
imagIne's user avatar
  • 83
0 votes
1 answer
162 views

RTrouble passing arguments to action

I know there are several posts on this topic. I have followed many of them as well as other resources on the web and thought I had it down, but it does not seem to be working. In my case, I have 2 ...
Daveh0's user avatar
  • 191
0 votes
1 answer
691 views

Variable inside shortcode or shortcode inside shortcode

I have a working shortcode, ie like this: [shortcode_name search="" show="url, color, size"] In this shortcode if I insert for example an email inside search (search="test@...
Kai's user avatar
  • 21
1 vote
0 answers
260 views

Shortcodes — Using add_action, add_filter in the shortcode

A client wants the following: User clicks on a specific button which takes them to a partner's site. If this is their first time clicking the link, they need to accept terms and conditions. If they'...
Tomasch's user avatar
  • 31
0 votes
2 answers
3k views

What is the alternative code to if (isset ($_POST) && !empty ($_POST) to avoid warnings?

I am trying to insert some php code to my WordPress website but it gives security warnings perhaps due to directly accessing $_POST variable. Instead of $name = $_POST['name'];, I can use $name = ...
Asmat Ali's user avatar
  • 139
0 votes
1 answer
1k 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, '...
tylorreimer's user avatar
0 votes
1 answer
57 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 $...
Pierre 's user avatar
0 votes
1 answer
1k 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....
Digital Essence's user avatar
0 votes
1 answer
2k 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 ...
user14055335's user avatar
0 votes
1 answer
17 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( $...
Vincenzo Piromalli's user avatar
2 votes
1 answer
26 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 ...
Ianthe MB Dempsey's user avatar
0 votes
1 answer
193 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 ...
Chris's user avatar
  • 3
0 votes
0 answers
262 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 ...
Colin G's user avatar
0 votes
1 answer
1k 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); ...
uixpider's user avatar
0 votes
1 answer
692 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 $...
dsax's user avatar
  • 1
0 votes
1 answer
388 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

1
2 3 4 5
8