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

Current page id returns the incorrect value

To get the current page ID outside of The Loop, you need to use get_queried_object_id(); ($wp_query-> is unnecessary). However, this will only work when you are viewing a single Page (so anything under Pages > All Pages in the back-end). If you are viewing the blog, an archive, or a category it will not be … Read more

Use global variables or function that returns said variables for site-wide private-ish WP settings?

No overriding benefit, other than collision avoidance and safeguard against unintended modification. Not sure if it makes you feel any better but WP core itself has many dependencies on global variables. I’m not saying that’s a good thing; just a fact. Also remember you have a database and functions to handle storing and retrieving options, … Read more

What is the use of $content_width?

$content_width is used to set the default width of embeds, for situations when an element needed to specify a width. This is how WP knew the width of the main content area. However, this was back before the push for responsive design, and modern CSS with fluid embeds and responsive breakpoints. So it isn’t needed … Read more

Best way to pass variables around a WordPress site?

It is possible to do this using the function wp_get_current_user(). This function will get the contents of the WP_User class. It can be stored in a global variable: global $current_user; $current_user = wp_get_current_user(); $current_user will then become an array matching the properties of WP_User for the currently logged in user. If no user is logged … Read more

Does WP have a global of $id?

If you are using netbeans and xdebug, or have set up your debugging environment correctly then you can observe the variables, objects e.t.c as they change. To see when they are created and what is contained within objects such as wp_query or wp_rewrite your posts->ID is set once the function wp() is called in wp-blog-header.php. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)