Convert PHP String to JSON String or HTTP query string

Hi
I am celebrating the functionalities of looper providers with WP query strings and JSON strings.
What I truly need, is a way to convert a PHP array string to a JSON string or directly to an HTTP query string.
Building a little function in my functions.php, as you described here (via the plugin Code “Snippets”) does not work, unfortunately.
Something like this:


But directly from PHP to HTTP query!
In my current case I need to order a WP query by two different meta values, and this can only be done by giving a JSON string, right?
Hope you have a little hint for me.
Thanks & kind regards,
Hannes

Hey Hannes,

Thanks for reaching out!

If you can share with us your desired layout or WP query, we can help you with your issue. Please provide us a full description on what you are trying to achieve.

Thank you.

Thank you for your fast response!
I need a way to convert a PHP array string to a JSON string or directly to an HTTP query string.
Building a little function in my functions.php, as you described here (via the plugin Code “Snippets”) does not work, unfortunately.

Hello @salilou,

What you are trying to do is not possible. Be advised that the Looper Provider Query String is following the WP Query and you need to supply the the query string. Using the http_build_query php function makes sure that the resulting HTTP query string is valid and correct.

So, if you have a PHP array, you will just have to run it with the help of the http_build_query php function to get the HTTP query string.

Thanks.

Thanks.

Thank you.
I may have expressed myself incorrectly here.
I would like to have the WP query string, as you described it here, converted into an HTTP string in functions.php. I need this function all the time since I’ve been working with the looper providers.
Kind regards,
Hannes

Hi Hannes,

You need to create the argument array in the PHP as described in the following thread and then you need to pass that argument variable in the http_build_query function to get the query string.

Hope it helps.
Thanks

OK thank you.
In my current case I need to order a WP query by two different meta values, and this can only be done by giving a JSON string, right?

Hello @salilou,

You can base your meta-value arguments on this documentation:

Hope this helps.

Ok thank you!
Have a wonderful time!

1 Like

Hey @salilou,

You’re most welcome!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.