Using global $post; to get featured image for custom post via WP_Query

$port_query->the_post(); should set the $post global. That isn’t the problem. The problem is that the you are trying to use $post before your secondary Loop runs (99% sure). You’ve hooked the bkg_featured_image() function to wp_head. wp_head runs in the header of the document, which, unless you are careful, will run before the other template code. … Read more

Defining a global array in functions.php?

In order to access a variable defined in the global scope you must reference it with the global keyword wherever you want to call it again. In your case, the function create_year_terms() must call the global $year_arr within its scope. Also, you can always get your variable in the global scope by using the $GLOBALS … Read more

Cannot update custom database table row

Before trying to write to the database, always validate the values you’re putting in: $fValid = true; if ( !isset( $payment->status ) ) { echo ‘Error: Payment status is not set’; $fValid = false; } if ( !isset( $order_id ) ) { echo ‘Error: Order ID is not set’; $fValid = false; } if ( … Read more

Add classname comment template from functions.php

You should consider hooking into the comment_class() and post_class() filters, if your theme supports it. Using the comment_class filter: We can add the following filter: /** * Add a custom comment class, based on a given comment author’s user meta field. * * @see http://wordpress.stackexchange.com/a/170443/26350 */ add_filter( ‘comment_class’, function( $classes, $class, $comment_id, $post_id ) { … Read more

How/where is the global variable $wp_registered_widgets filled?

As you can see here, $wp_registered_widgets is defined in wp-includes/widgets.php (as expected). You should be able to debug it by doing something like this: function yoast_print_active_widgets() { global $wp_registered_widgets; echo ‘<pre>’.print_r( $wp_registered_widgets, 1 ).'</pre>’; } add_action(‘init’,’yoast_print_active_widgets’); Then you could loop through the different stages, from init, to send_headers to wp_head and see where stuff goes … Read more

Global functions on WPMU

What you are looking for is a “MU-Plugin”– “Must-Use Plugin”.. Originally these were called “Multi-User Plugins” and were intended for exactly your purpose– to provide a way for site admins to enable functionality on all sites of an installation. Create a directory at /wp-content/mu-plugins/ and put your PHP file(s) in it. WordPress will load the … Read more