V
V
Vladimir Kulikov2021-07-17 16:19:46
WordPress
Vladimir Kulikov, 2021-07-17 16:19:46

How to pass a parameter to add_action in a function?

Hello, here is the URL and code:
https://test.ru?idGame=64

$id_game = $_GET['idGame'];
var_dump($id_game); // выводит число 64

function true_load_posts($id_game){
  var_dump($id_game); // выводит NULL string(0) "";
}
 
add_action('wp_ajax_loadmore', 'true_load_posts', 10, 1 );
add_action('wp_ajax_nopriv_loadmore', 'true_load_posts', 10, 1 );


Why isn't $id_game being passed to the true_load_posts function?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kalombyr, 2021-07-17
@it_proger29

Good day.
Because you have a function parameter and a global variable have the same name.
By the way, the wp_ajax_loadmore handler seems to have no parameters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question