What does the Global Variable $s represent?

It’s not a global variable; in fact it’s not a variable at all. It’s just placeholder within the sprintf() function. Take a look at the sprintf PHP function documentation. In the example you cite, the author is using the ‘argument swapping’ placeholder syntax: %n$t where %n is the placeholder number that corresponds to the argument … Read more

Where is this function’s callback getting its arguments from?

If you have a look at function do_meta_boxes() in wp-admin/includes/template.php then you’ll see this line close to the end of the function: call_user_func($box[‘callback’], $object, $box); That calls the callback function and provides the two arguments. The $box argument holds all the information about the metabox, like ID, title, callback function. In wp-admin/edit-form-advanced.php, which displays your … Read more

get_posts() and global variables

get_posts doesn’t modify global variables & is safe to use anywhere but setup_postdata does modify the global variables. Use the function wp_reset_postdata() just after the foreach loop. It reverses the changes made by setup_postdata. The thing it does is basically same as you did in your example, you just won’t need to worry about the … Read more

Use a variable created in get_header to calculate stuff in wp_footer

You need to redeclare the variable in your end_time() and also you don’t need the user to be logged in.. You can try the below answer. // LOAD TIME CHECKER function start_timer() { global $time_start; $time_start = microtime(true); } add_action(‘wp_head’, ‘start_timer’, 1); function end_time() { //try redeclaring the var global $time_start; echo ‘ <div class=”clearfix”></div> … Read more

Global Variable vs Local Variable

As @Milo pointed out, when you use code in OP $post_types is undefined inside the function, so WordPress will act just like it was not there at all. However, that means you are using an undefined variable, and if turn WP_DEBUG on you’ll see a warning, and so you can notice you are doing something … Read more

How do I pass custom shortcode-extracted variables (taxonomy) into a query function for WordPress RoyalSlider?

Two words – variable scope. Use a closure instead and pass $rstax through with use: add_filter( ‘new_royalslider_posts_slider_query_args’, function ( $args ) use ( $rstax ) { return array( ‘post_type’ => ‘carousel-slide’, ‘orderby’ => array( ‘menu_order’ => ‘ASC’ ), ‘tax_query’ => array( array( ‘taxonomy’ => ‘carousel-slide-category’, ‘field’ => ‘slug’, ‘terms’ => $rstax, ), ), ) } … Read more

Declare global var from Template File and use it in Functions.php

You can use the exact same filter in your template files. If you do need it in functions.php for any reason (maybe you have some additional processing) then you can use your own custom filter. functions.php: function my_custom_authorpage_title( $title ) { // process … return apply_filters( ‘my_title’, $title ); } add_filter( ‘wpseo_title’, ‘my_custom_authorpage_title’ ); author.php … Read more

Echo get_the_category() outside of loop (global?)

I realized that the_title(); can parse in file1.php outside of the loop, so why can’t the category and ID? The following solved my issue. // file1.php <div> <h1><?php the_title(); ?></h2> <?php $category_array = wp_get_post_categories($post->ID); $category_list = array(); foreach ( $category_array as $categories ) { $category_list[] = get_cat_name( $categories ); } $lister = implode(‘ • ‘, … Read more