S
S
skdon2015-11-05 11:32:35
WordPress
skdon, 2015-11-05 11:32:35

How to declare a global variable?

Good afternoon! Can you please tell me how to declare a global variable in Wordpress? And how to use it?
I need to pass variables from the page template to the function. I try so: in a template global $a; $a=5;
in function global $a; echo $a;
But nothing comes out :( The
task is as follows:
We display records on the main page, but not in the standard way 8f61ed4a7bc94301b4b31f10f52af1f6.png. I already asked, but no one answered.
full filling, so that there are no "holes". As a result, sometimes there are one or two records that are not shown.
At the bottom of the page there is a button "Show more", which Ajax loads the next batch of records.
I need to pass the ID of these records further to the output function, and when the news from the next page that has not yet been shown accumulates, then display the filled line.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
coderisimo, 2015-11-05
@coderisimo

Have you tried the standard PHP methods?

M
MetaDone, 2015-11-05
@MetaDone

*psychic mode*
you have the output of the variable before its definition, if your function is in the functions.php file in the theme. pass it through ajax for example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question