Support » Plugins » Hacks » Pass form values to query_posts

  • I am at a loss, and I’d really appreciate a pointer.

    I am trying to filter my posts using query_posts. The posts should be filtered by category. I am using an array to only return posts that belong to all the categories at once. I got this part working.

    The problem arises when I implement a form with 4 checkboxes, one per each category, which the user should select, then submit and see a list of posts that only belong to the selected categories.

    So this is my not working code so far:

    The HTML
    [Code moderated as per the Forum Rules. Please use the pastebin]

    The problem is that nothing is returned. The URL of the page does change including the selected checkbox value, but I dunno if that is worthless. When I try to echo $cats, I only get three commas, no category names, or values of sort.

    Do you have an idea if I am passing the variables the wrong way or anything else? Thanks in advance.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Maybe You should try something like this:

    working with the category name

    $catnam = $_GET[“catnam”]; // or $_POST[“catnam”];

    working with the category id

    $catid = $_GET[“catid”]; // or $_POST[“catid”];

    Hope it helps you.


    Hi, thanks Alvaron

    Probably you replied after the mod removed my code (@mod: sorry for the slip by the way.)

    So here ya go with pastebin:
    Hope this makes things clearer for you.

    I saw your post on your blog and the issue is not how to filter posts from one category or multiple, either getting posts from all those categories or just those that belong to all the categories at the same time, as that would be
    query_posts(array('category__and'=>array(1,2,3,4),'showposts' => -1)); ?>

    My issue is: I want to use the latter function (so get posts that belong to multiple categories at the same time), but I want users to select what these categories should be from a number of checkboxes. I have no idea how to pass the values of the checkboxes to the friggin’ array!! It is driving me nuts (of course I am a total rookie at this, so…)

    I will try and see if your suggestion can help in any way though!


    @alvaron No luck at all with your advice. I must be missing the proper way of formatting the form data. I am not sure I am doing it correctly. Could you please take a look at my pastebin data and see if there are macroscopic errors I should correct? I have tried various combinations with id, name and value, but nothing works.

    Sorry for bumping, but I am still, well, bumping my head against the wall over this.. anyone please?

    You have to use $catid like…………..>>>

    $catid = $_GET[“catid”]; // or $_POST[“catid”];

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Pass form values to query_posts’ is closed to new replies.