0

On my site, the following array parameters will work fine through the WordPress query_posts() function in an ajax request:

 $arr_params= array
    (
     'post_type'=>'university',
      'tax_query' => array(
         array(
        'taxonomy' => 'uni',
        'field' => 'slug',
        'terms' => 'stanford'
        )
        )

    );

However is it possible to build a link using these arguments? I want to display a link on my posts, which when clicked, re-loads the WordPress loop using the above parameters.

I've tried

add_query_arg($arr_params,get_permalink());

but have not had any success

5
  • What is the finished URL supposed to look like? Your $arr_params has a couple of sub-arrays, and I can't figure out what correct query string ought to be. Commented Nov 4, 2013 at 19:12
  • I actually don't know what it should be. I was hoping it could be created magically, but I don't think get_permalink can handle the tax_query Commented Nov 4, 2013 at 19:19
  • 1
    You might be able to reverse engineer what the query would need to be, to get that array, but yes, I think it might be a little too complex for add_query_arg to do all the work. Commented Nov 4, 2013 at 19:21
  • thanks, just took a little experimentation and I got it pretty quickly...shame I posted the question, but maybe it will help somebody else Commented Nov 4, 2013 at 19:44
  • Could you add what you did as an answer? You can accept it when you get change, but I'm curious to see what you did! Commented Nov 4, 2013 at 19:46

1 Answer 1

1

The add_query_arg function does not take a taxonomy query as seen in the question. The following array produced the result I wanted:

   $arr_params= array
    (
     'post_type'=>'university',
     'taxonomy' => 'uni',
     'terms' => 'stanford'
    );


echo add_query_arg($arr_params);

This is what it returns:

/?post_type=university&taxonomy=uni&terms=stanford

Sign up to request clarification or add additional context in comments.

1 Comment

yea I was kicking myself that I wrote a whole question before attempting that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.