WordPress.org

Forums

User defined visibility of categories based on check boxes (2 posts)

  1. jparry
    Member
    Posted 2 years ago #

    Hi All,

    This is my first post and first time working with Word Press so here goes.

    I am in the process of modifying a friends site so that a user can choose categories via check boxes on the main home page so then the posts showing will reflect their choice.

    So far, I have modified the header to include the check boxes and code needed to save the selections back to a cookie so that they can be reloaded when the visitor next returns.

    The part I am stuck on is now how to filter the page based on the check box values. I was going to use the values from the check boxes to choose category id's but when I started to look at the built in wp_query documentation but it looks like its php based and obviously, being server side and my controls being on the client side, I can't work out how to 'drive' the filter.

    And guidance would be greatly received as I think I am heading towards a dead end.

    Thanks in advance,

    James

  2. bcworkz
    Member
    Posted 2 years ago #

    The checkbox states need to be sent back to the server so it can do a new query based on the selected categories. The new query results are then sent out to the client as a new page.

    If you submit the checkbox form as a GET request, the selections should get parsed into query variables OK, but the query parser will not know what to do with them, You will need to hook the 'pre_get_posts' filter to interpret the checkbox states into something the query parser will understand. Once you do this, WP will properly fill the request with an appropriately filtered new page.

Topic Closed

This topic has been closed to new replies.

About this Topic