Viewed   104 times

I am having trouble trying to pass an extra variable in the url to my WordPress installation.

For example /news?c=123

For some reason, it works only on the website root www.example.com?c=123 but it does not work if the url contains any more information www.example.com/news?c=123. I have the following code in my functions.php file in the theme directory.

if (isset($_GET['c'])) 
{
  setcookie("cCookie", $_GET['c']); 
}

if (isset($_SERVER['HTTP_REFERER']))
{
  setcookie("rCookie", $_SERVER['HTTP_REFERER']);
}

Any Ideas?

 Answers

3

There are quite few solutions to tackle this issue. First you can go for a plugin if you want:

  • WordPress Quickie: Custom Query String Plugin

Or code manually, check out this post:

  • Passing Query String Parameters in WordPress URL

Also check out:

  • add_query_arg
Sunday, October 30, 2022
2

I don't know if there is a default feature for this or not but I have an idea as how to achieve it.

You can create a custom template for this and in that template get the query string by get_query_var() and then use WP_Query cat and tag argument to fetch your posts belonging to that cat/tag.

Here is a sample working code:

$cat_id = get_query_var('category');
$tag_id = get_query_var('tag');
$args = [
    //...
    //...
    'post_type' => 'post', //<-- Replace it with your custom post_type
    'post_status' => 'publish',
    'tag_id' => $tag_id, //replace tag_id with tag if you are passing tag slug
    'cat ' => $cat_id //replace cat with category_name if your are passing category slug
    //...
    //...
];

// The Query
$query = new WP_Query($args);
if (!empty($query->posts))
{
    //print_r($query->posts);
    foreach ($query->posts as $post)
    {
        //Your filtered post
    }
}

Hope this helps!

Monday, August 8, 2022
 
5

Answering my own q:

The pointers in the answers above were useful and got me going on the right track, but I kept hitting a snag in that whenever the url in question was invoked it kept calling index.php.

I then came across http://mikeschinkel.com/blog/restful-web-services-in-wordpress-plugin/ where he goes into an explanation and provides an answer that requires a template_redirect action to ensure that control is where you want it.

Sunday, August 7, 2022
2

Try this:

jdbc.url=jdbc:mysql://xxxx.xx.xx.xx/dbName?sessionVariables=group_concat_max_len=204800
Tuesday, September 27, 2022
1

Change

url: 'https://graph.facebook.com/?pageid/?access_token='+pageid+accesstoken,

to

url: 'https://graph.facebook.com/?pageid='+pageid+'&access_token='+accesstoken,
Monday, September 26, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :