best practice for query string values – get_query_var always empty for my value supplied in query string

You get the exact unchanged value with: $event_id = filter_input( INPUT_GET, ‘event_post_id’, FILTER_VALIDATE_INT ); Here I added the validation filter directly, but you can even move that to separate code for more complex cases. WordPress’ query variable handling is for cases in which you want to allow changes to the values before they reach your … Read more

How do I dynamically render an InnerBlock inside a dynamic block?

Instead of removing the question, I’ll answer the question myself for those that seek to find the same answer. My InnerBlock was called counter-list.php, which causes a problem as I have a counter_list_render_callback function. When looping through all my blocks, it tries to find counter-list_render_callback which is an invalid function name and therefore fails to … Read more

Show User’s Current Time

If you don’t have a problem using a api you can do the following. // check if user IP exists if (!empty($_SERVER[‘REMOTE_ADDR’])) { // get user data based on IP (not always correct) $user_ip_data = file_get_contents(‘http://ipinfo.io/’ . $_SERVER[‘REMOTE_ADDR’] . ‘/json’); // check if is json object if (!empty($user_ip_data) && $user_ip_data[0] === ‘{‘ && substr($user_ip_data, -1) … Read more

How to render a time-of-day string like ’16:42′ with a site’s chosen time format?

The trick here is using wp_date() in a peculiar way, giving it the time of day in seconds (as if it were 1970-01-01 16:42:18), then asking for it to be formatted in UTC. $time=”16:42:18″; if ( preg_match( ‘/^\d\d:\d\d:\d\d$/’, $time ) ) { //validate the $time $ts = intval( substr( $time, 0, 2 ) ) * … Read more

“Plugin could not be activated because it triggered a fatal error.”

The recommended way to write that function would be: function ce3_cleanup() { global $wpdb; $wpdb->query( “update $wpdb->postmeta set meta_key=replace(meta_key,’cb2_customHeader’,’_cb2_customHeader’) where meta_key like ‘cb2_customHeader'” ); $wpdb->query( “update $wpdb->postmeta set meta_key=replace(meta_key,’cb2_customTitle’,’_cb2_customTitle’) where meta_key like ‘cb2_customTitle'” ); } register_activation_hook( __FILE__, ‘ce3_cleanup’ );