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 ...

learn more… | top users | synonyms

0
votes
2answers
39 views

Assign custom parameter to each post in query

I'm trying to add an incremental variable to each post that comes up in a series of queries. The purpose is to calculate a weight for each result in order to be able to order everything later. This ...
0
votes
0answers
9 views

Class For Dependent Child Post Data using get_posts()

I want to use a class to display various parts of a dependent post via a class. This is my first stab into OOP, so please be try to be somewhat gentle, if possible. :) At a high-level I have a two ...
0
votes
1answer
808 views

Passing variable as permalink URL

I've been trying to adapt the rewrite functions described here with little success: Passing variables through permalink structure WordPress permalinks and custom $_GET Variables The structure of ...
0
votes
1answer
41 views

Persistent Shortcode Attribute Variables using WP_Query and WP AJAX

I'm trying to: list posts using a shortcode using WP_Query have that list use pagination have that pagination use AJAX ...and - where I'm getting stuck - manipulate my list via shortcode attributes ...
0
votes
0answers
32 views

Pass Variable from Function to Shortcode

I realize that this may be as much of a PHP issue as a WP issue, but I'm posting it here because it does pertain to shortcodes and have some WP-specific functions mentioned. Basically, What I'm ...
0
votes
1answer
504 views

Variable scope producing undefined variable notices in included files

I'm building a Wordpress Theme and on the front page the user is able to select how they would like to order their posts. I've then created two functions that take the users selection through the ...
0
votes
1answer
26 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
22 views

Wordpress custom widget undefined variable notice

I am developing a theme and I have created a custom widget for it. When I turn on debug mode I get the following notices, NOTICE: wp-content/themes/integral/inc/widgets/feature_widget.php:92 - ...
16
votes
3answers
6k 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 ...
0
votes
1answer
27 views

How do I share variables between two functions?

So...here is part of my code for a plugin. I'm a newb of sorts so be kind. I've read up on global variables but I can't seem to get it to work and I've read you shouldn't use them anyway. So what ...
0
votes
0answers
15 views

modifying variables passed to the Wordpress LOOP, with IF/THEN?

good evening, i'm trying to make my coding as modular as possible. my site uses three different LOOPs, each to accomplish a different task with my posts/pages, and i've got each loop on its own file, ...
1
vote
0answers
115 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 ...
1
vote
1answer
28 views

How can i use the same template file with a widget and category loop?

i wrote a widget and i want to use category template which is located in "themename"/template-parts/content.php". <?php // Category.php while ( have_posts() ) : the_post(); get_template_part( '...
0
votes
0answers
47 views

Inject a user specific ID into first URL segment

I've got a site that deals with affiliates and needs to inject an affiliate ID directly into the URL string. So for instance if an affiliate's ID is 12345, I would like to inject 12345 into the first ...
1
vote
2answers
593 views

Echo one category as title when post has multiple categories?

UPDATED QUESTION to be CLEARER Here's my situation: Wordpress top navigation has several menu items that jump to an array of posts within a specific category. For example, if you click "necklaces" ...
1
vote
1answer
24 views

Count the number of times the search form template gets included on a page

I've got a template that has a search form in several locations. Each search form is identical, containing a text input, two radio buttons, two labels associated to the radio buttons, and a submit ...
1
vote
2answers
39 views

Using variable in two functions

What would be the right way of using variable with same data in two functions? Is next approach good practice? I have a few of these variables set up in functions.php $a = array('asdf', 'asdf', '...
0
votes
2answers
34 views

Passing stored variables to add_filter

I am working on a site where the page titles are generated dynamically from external data sources. So obviously, Yoast SEO/WordPress SEO doesn´t know anything about the correct title, description, ...
0
votes
0answers
31 views

Adding extra rows to form, and saving values entered.

I am attempting to create a quote-form where the user can add as many items as necessary. I would then like to take the values entered and output them to a html table in an email. Here is the ...
1
vote
2answers
281 views

Can wp_list_comments output into variable?

Is there any way how to output wp_list_comments() into a variable? Something like $output = wp_list_comments(array('reverse_top_level' => false ), $comments); I am writing a plugin and it would ...
0
votes
1answer
19 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
1answer
15 views

Is it advisable to use $post->comment_count instead of get_comments_number( $post_id )

I was learning from the WordPress codex about global variables and after var_dump($post) I found out that $post has a property called comment_count I was wondering whether I can directly use $post-&...
3
votes
1answer
144 views

Calling a wp_query $posts causes a 500 error

I had a very basic wp_query, below: // WP_Query arguments $args = array ( 'post_type' => array( 'post' ), 'post_status' => array( 'draft' ), 'posts_per_page' ...
0
votes
0answers
25 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
2answers
7k 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 I ...
0
votes
0answers
65 views

setcookie() using $_GET variables in plugin

I'm trying to store a few analytics tags inside a session cookie to be used in subsequent pageviews. Essentially what I'd like to do is this; if ($_GET['utm_source'] != "") { setcookie("...
0
votes
1answer
609 views

Why won't the action hook wp_head accept parameters?

I'm working on a plugin that adds scripting to the head using add_action('wp_head',..); I have to pass a variable to the function to get my desired result. To test this I'm simple "echoing" out ...
0
votes
2answers
61 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
3answers
74 views

ACF allow zero as a value

I would like to have 0 to 5, and "n/a" as possible values, however this code will output "n/a" when I want it to output a zero. How can I get it to output "0"? ("n/a" is the placeholder if no value ...
0
votes
1answer
23 views

echo var into wp_query

Im trying to echo out a value grabbed from a ACF field but I think im doing something wrong, could someone help me? <div class="news"> <div class="container"> <div ...
0
votes
2answers
56 views

how can I include some custom variable from functions.php?

For example, if I add this code to functions.php: $mysite_address_url="http://my-site.com"; And then add this to one of my .php template files(like index.php or header.php): <?php echo($...
0
votes
1answer
39 views

Create a variable with string, array or multiple values

I'm running some functions that will allow a user to register their own custom templates to my custom theme from an external directory. They can see these page templates in the wp-admin and they ...
1
vote
2answers
354 views

Call global variable array() in woocommerce child/template

So I have this in my functions file - it defines the products that are not eligible for free shipping. It works everything is fine. //functions.php function my_free_shipping( $is_available ) { ...
2
votes
1answer
35 views

Remove HTML content if attribute is not set / variable attributes

So I'm creating a shortcode that uses the standard bootstrap carousel. It works completely fine as long as all the 3 slide attributes are entered correctly but obviously if only 2 are set and the ...
0
votes
1answer
53 views

Dynamically adding filters

I have a function that I'm trying to get an array in it to use in a callback to dynamically add filters. Here is the function that I need to retrieve the array keys from ( in the $classes variable ): ...
1
vote
2answers
44 views

Declaring <?php ?> in variables [closed]

I need to put the PHP <?php global $' . $icon_var . '; echo $' . $icon_var . '; ?> inside the variable of a custom menu structure, but it gets commented: <a href="http://slembas.esy.es/">...
-2
votes
1answer
38 views

How to pass variable to functions.php?

I have a variable, created in page.php, and would like to pass this to a function in functions.php. Possible?
0
votes
0answers
185 views

Get WordPress Page Title, ID, or Template of the Page an AJAX Request is Made From and Pass as Variable in AJAX

I have a page template that includes a region that holds links to a series of video custom post types. Each of the links is tagged with an 'ajax-link' class so that through an AJAX request I can pull ...
0
votes
2answers
74 views

How to pass a variable for key/value pairs in an argument?

For example, this works: 'default' => '#ffffff' But this does not: $white = '#ffffff'; 'default' => $white How can I pass variables to key/value pairs? Here is a more complete example for ...
0
votes
1answer
33 views

Create a Wordpress shortcode using PHP [duplicate]

I am currently using the following code within single.php (after the_content) This gets the store_name from custom field as $merchant from the post and then returns a list of products from that ...
0
votes
1answer
23 views

Where and how to define variables for URLs etc

I have one online version of a site, and one developer version which I am working and making changes on. If I have a form with a url which the user will be redirected to: <input type="hidden" ...
5
votes
2answers
498 views

Using Wordpress public query variables

Good morning. I am trying to query various Wordpress pages, using public query variables, for example http://dmkim1979.ru/?p=37 // single post http://dmkim1979.ru/?page_id=40 ...
0
votes
1answer
62 views

Declare global variable that can be used on other function

I have AJAX image upload function where I can get attachment_id value. I want to save that as global variable and use it in different function that sets post thumbnail when it's exist. This is what I ...
0
votes
2answers
240 views

Passing attributes to shortcode dynamically

Can I pass dynamically to shortcode attributes like as the following example shows [ authoorsposts author = get_the_author_id(); ]
0
votes
0answers
20 views

How to use a variable as key in an array at Customizer select setting

I'm trying to add a Customizer 'select' setting to my theme with the path to a CSS file as key in an array, like so: $wp_customize->add_control( 'control_something', array( 'label' ...
1
vote
1answer
84 views

How to fix Uninitialized string offset: error on a checkbox in WP Settings API

I am trying to create an options page with a checkbox field. The checkbox is working fine but when I uncheck it and save settings, an error string shows on Notice: Uninitialized string offset: 0 in ...
1
vote
2answers
33 views

Global variables during plugin activation , deactivation and uninstall operarations

For activation hooks codex states that you have to be explicit on globals: A note on variables during activation But that seems not to be working on uninstall.php If i define a global in my main ...
0
votes
3answers
57 views

Action 'init' function doesn't return variable

I have a function which checks if $_POST is set (a form which submits to the same page). I need to have it initialized before the page is loaded because the function will do a header redirect if the ...
0
votes
1answer
148 views

Validate form in functions.php, send errors back to template

I have a form in a template that upon submission should be validated, and any errors should be displayed, and if no errors, insert the data into the database. I'm new to wordpress, but my idea was ...
0
votes
1answer
60 views

Define PHP variable from a seperate API if statement

I am trying to put together a function that will echo certain text based on a range of numbers. One of number(s) I am trying to compare against is echoed in my template as such -- <?php if ( ...