I am working on my first block-based theme, and trying to leverage theme.json as much as possible. I would like to allow client to change the the fonts, colors and other variations defined in the theme.json globally, for the whole site, and in the tutorials over the net I saw this can be done in the Global Styles menu. But, I don't see Global Styles menu in any of the block-based WP sites I have access to, including the Gutenberg …
My custom PHP script works on my PC over localhost. But, when I upload my code to the 'live' WordPress site, The $GLOBALS values are just null even they work on my localhost. (Nothing wrong with the database connection). Is the $GLOBALS not working on WordPress? My code is something like this one below: $get_value = $db->query("SELECT * FROM mytable")->fetch(); $get_variable = $get_value['myvalue']; function myfunction(){ return $GLOBALS['get_variable']; }
Plugin in question: http://dimsemenov.com/plugins/royal-slider/wordpress/ Background: This is a great plugin, and it features a 'post' version where the slider pulls content from posts. However, the taxonomy for the posts that it's pulling has to be set at the slider settings level in WordPress, it can't be done via shortcode (that we know of). The plugin author does offer a way to override the default query here: http://help.dimsemenov.com/kb/wordpress-royalslider-advanced/wp-modifying-order-of-posts-in-slider Aim: create a custom shortcode through which we can pass custom attributes, and …
I have an API Request for weather and the account of this weather stuff has a limitation of requests per minute. In my theme I have the weather information twice on the same page. So if I would make a function of the request it would fire twice. I thought about a global variable, where I could save the request once and grap this variable where ever I want. Is this a good idea? I read something about, that global …
I have a function like this: add_settings_field( 'contact_phone', 'Contact Phone', 'settings_callback', 'general'); That works. It calls settings_callback. Cool. The problem I have with this is: I don't want to have to define a callback function for every setting I add, if all I'm doing is echoing out a little bit of stuff. function settings_callback() { echo '<input id="contact_phone" type="text" class="regular-text" name="contact_phone" />'; } Why on earth should I have to do that? The id, class, and name should all be …
Ultimately to keep it real simple, on a custom query page, I have a global variable that I pull from a previous page. When I go to page 2… the global variable is blank. Page 1: Define global variable. Link to another page Page 2: When on page 2, i call global variable, it works fine On this page 2, it is a custom query. When I go to page 2, the global variable is now blank. It seems the …
I have a custom post type called projects, and its archive is at /projects, on the archive page I get notices Notice: Trying to get property of non-object every time I try to access the $post i.e. $post->post_name. Is this intended behaviour? Should I just accept that and always check the availability of $post before using it? if (!empty($post)) { // Do something with $post }
UPDATE: My original question has been solved, but this is turning into a valid discussion about why not to use global variables, so I am updating the question to reflect that. The solution was <?php global $category_link_prop; echo esc_url( $category_link_prop ); ?> as @TomJNowell suggested. UPDATE 2: I now have it doing exactly what I wanted. But I'm still using global scope and would be happy to find a better way. I am trying to set up a whole bunch …
People are often confused about how to get data from global objects/variables Question: In which ways can you inspect global variables? This Q was written because it's needed pretty often over here at WA. I just wanted to have it as a fav to link over here (people often don't take a look at github gist links). Feel free to modify the example if something is wrong or you think that the explanation is missing something. If you want to …
I have register a route for edit_audience register_rest_route( 'ilms_plugin', 'edit_audience', [ 'methods' => 'POST', 'callback' => 'edit_audience', 'permission_callback' => '__return_true', ]); I try to get the global variable $menu in the edit_audience callback function. function edit_audience($data) { global $menu, $submenu; error_log("menu=".print_r($menu, true).";"); error_log("submenu=".print_r($submenu, true).";"); } But nothing return from the $menu global variable. I am doing this way to change the menu and submenu capability from a form request. Is there any way to change the menu and submenu capability …
I made a shortcode, it does most of what I need it to do. Except for a filter I need the post id of the page the shortcode is placed. (to get some linked custom field values) And I can't expect the persons who are going to use this shortcode to get the post ID and use in an parameter for the shortcode. So I need the shortcode itself to get it. Simple. global $post; $post_id_i_need = $post->ID; But on …
I'm trying to optimize my functions.php file as I have a Woocommerce site with a bunch of customizations to the theme. Currently, my functions look like the following: add_action('wp_footer', 'enqueue_product_modals'); function enqueue_product_modals() { global $product; //Accessing the Global $product_id = $product->get_id(); if (is_product()) { //Standard Modal: require_once 'modal-product.php'; if (has_term('guitar-pickups', 'product_cat', $product_id)) { include_once 'modal-polarity.php'; }; if (has_term('mini-humbuckers', 'product_cat', $product_id)) { include_once 'modal-minihum.php'; }; } } add_action('woocommerce_after_single_product_summary', function () { global $product; //Accessing the Global Again $name = $product->get_name(); if …
I set global variables for some custom user data in my functions.php to use them in navigation inside header and footer. if (is_user_logged_in()) { # users wordpress id global $user_id_wp; $user_id_wp = get_current_user_id(); # users meta page id global $user_id_meta; $user_id_meta = userMeta(get_current_user_id()); # users uuid global $user_id_uuid; $user_id_uuid = get_field("user-uuid", $user_id_meta); } Those variables cannot be used inside header.php and footer.php where I need them. Cannot be used means var_dump($user_id_meta) results in NULL, while userMeta($user_id_wp) shows the correct values …
I added a custom field with comment form. Below is my code.First function return post id when using var_dump function.But the last function return NULL always. class Post_Rating_Public_Helper { public static function prp_change_comment_form_defaults($commentdata, $comment_id = null ) { global $check; global $wpdb, $post; //// get rating value from database $ratingValues = $wpdb->get_results( "SELECT meta_value FROM ".$wpdb->prefix."commentmeta WHERE meta_key = 'rating'"); $results = $wpdb->get_results( "SELECT option_value FROM ".$wpdb->prefix."options WHERE option_name = 'prp_settings'"); var_dump($post->ID); // return post id $a = unserialize($results[0]->option_value); $b …
Setting up a WP multisite instance - the client has an existing ontology / set of categories that they want to classify all content across the set of blogs. Also the desire is that any new categories would be added at the 'network blog' level and synced to the other blogs. What's the best way of doing this?
Im working on a project in Wordpress that enqueues multiple .js files where each file adds a new method to a global javascript object, this in order to make the desired methods available only if certain conditions are met like is_page(), is_singular(), etc. The purpose of adding the methods in this way besides avoiding polluting the window object with multiple global functions is mainly to be able to call this methods in a inline javascript added dinamically with wordpress functions …
I have create a custom post object with custom post metas. Like this: $post->custom_meta = get_post_meta(); $custom_post = $post; Am I how to define the $custom_post object to global in master level? Can I request any file it like single.php global $custom_post; the_title(); echo $custom_post->custom_meta; or index.php global $custom_post; // The Loop if ( $custom_post->have_posts() ) { echo '<ul>'; while ( $custom_post->have_posts() ) { $custom_post->the_post(); echo '<li>' . get_the_title() . '</li>'; echo $custom_post->custom_meta; } echo '</ul>'; } else { // …
Following this great tutorial I've implemented Ajax pagination with scrolling: https://www.billerickson.net/infinite-scroll-in-wordpress/. Now, I've added a second Ajax call to filter the posts by category and I would to make pagination works also for the filtered posts. So I thought to make something like this in function filter_posts() in functions.php: function filter_posts() { global $wp_query; $args['category_name'] = $_POST['passed_slug_via_ajax']; query_posts($args); [loop] wp_send_json_success( $data ); }; I thought that in this way, ie using query_posts, the current query global $wp_query; was altered to …
I am trying to insert some php code to my WordPress website but it gives security warnings perhaps due to directly accessing $_POST variable. Instead of $name = $_POST['name'];, I can use $name = filter_input(INPUT_POST, 'name'); however I am not able to figure out what alternative piece of code I should use instead of if(isset($_POST) && !empty($_POST)) { //some code }? Thanks for your help in advance.