Force Rewrite Query Var On Hierarchical (Nested) Page

Just in case any one needs this: /* Register Query Var —– */ function my_queryvar_params( $query_v ) { $query_v[] = “my_var”; return $query_v; }; add_filter(‘query_vars’, ‘my_queryvar_params’); /* Rewrites —– */ function setup_filter_rewrites(){ add_rewrite_rule(‘^my-parent/my-page\/([0-9]+)\/?’, ‘index.php?pagename=my-parent/my-page&my_var=$matches[1]’, ‘top’); // As @Milo mentioned, the pagename paramenter needs to reflect the path hierarchy }; add_action( ‘init’, ‘setup_filter_rewrites’ ); /* Force … Read more

How to call code when adding WooCommerce menu items via woocommerce_account_menu_items

One needs to create an action hook ‘woocommerce_account_[myendpoint]_endpoint’: add_action(‘woocommerce_account_’ . $endpoint . ‘_endpoint’, ‘my_endpoint_content’); function my_endpoint_content() { //content goes here echo ‘My content goes here’; } http://hookr.io/actions/woocommerce_account_key_endpoint/ So, putting a few different sources together, to add a new menu item to the Woocommerce My Account dashboard one needs something like: <?php add_filter(‘woocommerce_account_menu_items’, ‘add_my_menu_items’); function add_my_menu_items($items) … Read more

Rewrite Rule for Post Meta

Okay! So I got this working by just changing the rewrite_rule to include the event… function aca_award_cat_rewrite_rule() { add_rewrite_rule( ‘^awards/([^/]*)/award-category/([^/]*)/?’, ‘index.php?competition=$matches[1]&award_category=$matches[2]’, ‘top’ ); }

Query_vars support in Rest API

correct me, if i’m wrong, but query vars are not processed in REST requests. but there is other ways to make this work. not really sure, if this will help with your problem but hopefully it is at least a push in the right direction function so380236_rest_cpt_query($args, $request) { $query_params = $request->get_query_params(); if (!array_key_exists(‘city’, $query_params)) … Read more

How to append a query string to pagination?

Refer this: Paginate Codex I can see that you are using custom query so you put this below and outside the while loop <?php global $wp_query; $big = 999999999; // need an unlikely integer $args = array( ‘base’ => str_replace( $big, ‘%#%’, esc_url( get_pagenum_link( $big ) ) ), ‘format’ => ‘?page=%#%’, ‘total’ => $wp_query->max_num_pages, ‘current’ … Read more

Code syntax error, “userfullName undefined”

You are missing the ‘echo’ userfullName = <?php $current_user->display_name;?> should be var userfullName = “<?php echo $current_user->display_name;?>” AND notice that I put quotes around that too. BUT!!!! You should really look at using wp_localize_script for declaring javascript variables. Example: add_action(‘wp_enqueue_scripts’, ‘fobu_front_scripts’); function fobu_front_scripts() { global $blog_id; $params = array( ‘site_url’ => site_url(), ‘blog_id’ => $blog_id … 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

Why I can not I use the variable outside my function?

The problem here is order, the $post variable isn’t available from the moment WordPress is loaded, it needs to process the request, put together a database query, and retrieve the post first. Time travel is necessary for your code to work as you expected. Your themes functions.php and plugins will be loaded before this happens … Read more