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
51 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
17 views

Creating a Variable Product

I can’t create a variable product, I used many options, also examples of codes on this resource, a simple product is created easily, impossible create a variable product with options and prices, any ...
Lerry's user avatar
  • 111
0 votes
0 answers
25 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
24 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
18 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
  • 263
1 vote
0 answers
19 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
0 votes
0 answers
384 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
168 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
23 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
216 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
968 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
  • 11
0 votes
0 answers
50 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
322 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
53 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
389 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
209 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
567 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
25 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
148 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
1k 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
202 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
16 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
1 answer
1k 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
470 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
  • 134
0 votes
1 answer
176 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
  • 11
0 votes
1 answer
140 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
317 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
190 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
2k 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
  • 129
0 votes
1 answer
239 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
44 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
804 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
25 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
141 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
179 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
687 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
125 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
286 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
2 votes
1 answer
129 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 ...
Charlie C's user avatar
0 votes
1 answer
46 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 ...
ralphjsmit's user avatar
0 votes
0 answers
25 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 ...
rhel's user avatar
  • 1
1 vote
1 answer
2k 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&...
Hanno K's user avatar
  • 11
0 votes
0 answers
63 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 '...
Bruce Banner's user avatar
1 vote
0 answers
135 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 ...
Gwell's user avatar
  • 11
0 votes
1 answer
117 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 ...
Aisha's user avatar
  • 1
0 votes
2 answers
454 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 ($) { ...
Shweta Danej's user avatar
0 votes
2 answers
793 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 ...
Kristýna Šulcová's user avatar

1
2 3 4 5
8