What does arg mean in WordPress

It is just the naming convention which increases code readability. you can replace it with any name it won’t affect your code.

Example I:

$args_user = array(
    'number' => 10
);
$user_query = new WP_User_Query($args_user);
$users = $user_query->get_results();

//------------------------------------------

$args_post = array(
    'numberposts' => -1,
    'post_type' => 'post'
);
$posts = get_posts($args_post);

Example II:

$my_args_1 = array(
    'number' => 10
);
$query_1 = new WP_User_Query($my_args_1);
$data = $query_1->get_results();

//------------------------------------------

$my_args_2 = array(
    'numberposts' => -1,
    'post_type' => 'post'
);
$data = get_posts($my_args_2);

Both the code example I and II will have same output, but first example has a good user readability and if you have a long method/code then after seeing the variable name you can easily recognized.

Leave a Comment