Articles of query variable

Add pagination to a template loaded by query variable

I have set a query_var,called men, which loads a custom template displaying men’s clothes. The rewrite rule is as follows: add_rewrite_rule(‘collection/men/?$’,’index.php?post_type=collection&men=yes’,’top’); and the template redirect code is this: if(get_query_var(‘men’) && is_post_type_archive(array(‘collection’))){ add_filter(‘template_include’,function(){ return get_template_directory().’/clothes-men.php’; }); } The code works, rewrite working as expected ie. localhost/sample-site/collection/men loads the template. The problem comes when I add standard […]

Rewrite Rule for Custom Page with Query Vars in URL

Background I have a a page called ‘listen’ with a custom template, which runs a custom wp_query that uses the ‘show’ variable in the URL. The following example works… What I Want I want to be able to get rid of the ?show= part of the url, and format it as follows… What […]

Rewrite URL Parameter And Force 'Pretty' Permalink

I’m trying to pass a variable via a URL parameter and rewrite + force ‘redirect’ it. In other words, I have: /dir1/dir2/?my_var=123 and I want: /dir1/dir2/123/ Through the following code in my functions.php file, I am able to achieve that: function setup_filter_rewrites() { add_rewrite_rule(‘dir1/dir2/([^/]*)/?’, ‘index.php?pagename=dir1/dir2&my_var=$matches[1]’, ‘top’); } add_action( ‘init’, ‘setup_filter_rewrites’ ); function setup_filter_query_vars( $query_vars ) […]

Pass form input via url variable

I have an input field on the homepage of my site that asks the user to input their email address. When the user clicks the submit button, I would like to redirect them to another page on the site (which will contain a form for name, age, etc.) and pass their email address as a […]

How to pass a query string to another page on the same site?

I am using a plugin that uses unique user ids (uuid) to let visitors access some information. They receive this information by email. This works great, if the visitor opens the direct page with a url containing the query string, for example: As soon as the user opens the link and navigates to another […]

Force Rewrite Query Var On Hierarchical (Nested) Page

I want to use a hierarchical (nested) page with a query var to pull dynamic content. I had things working when the page wasn’t a child of another page, such as: However, when I made my page a child of another page, my query_var no longer works, e.g. My code /* Register Query […]

Code syntax error, “userfullName undefined”

I’m working on a WordPress site that is using Google Visualization API Query Language to get a chart onto a page, using the data of the current logged in user. I’m using the function wp_get_current_user() to get the user data and $current_user = wp_get_current_user(); I’ve been working on this for days, this is the closest […]

How to append a query string to pagination?

I would like to append 2 variables from page 2 onwards in my loop. This is my normal category page This is what I would like on pages: 2, 3, 4, 5 etc The Loop: $args = array ( ‘category_name’ => ‘news’, ‘posts_per_page’ => 5, ‘paged’ => $paged ); $news_loop = new WP_Query($args); […]

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

I am writing a little plugin, to extract the post ID and them use it for some queries. Of course if I write: function my_callback_function() { $aa = ‘hello world!’; echo $aa; } call_user_func(‘my_callback_function’); // returns: hello world but if I write: function my_callback_function2() { global $post; // get post iD $aa = $post->ID; echo […]

Redirect old query string URLs to new add_rewrite_rule URL

I have a custom page like this: /show/ is a WordPress page with a postid of 540. I added a rewrite rule to convert the URL to: Here’s the code I’m using in my theme’s functions.php for the rewrite: add_action( ‘init’, ‘init_custom_rewrite’ ); function init_custom_rewrite() { add_rewrite_rule( ‘^show/([^/]*)/([^/]*)/?’, ‘index.php?page_id=540&id=$matches[1]&n=$matches[2]’, ‘top’ ); } add_filter(‘query_vars’, […]