• I’m developing a website with custom post fields (projects). The projects are organized by taxonomies (states). I need to create a drop down menu that the user selects which projects he would like to see, based on the state. But the challenge is: how to do this globally? When the user clicks in a internal page, the content remains filtered. Should I use cookies? How?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m not sure I follow. An example narrative of a specific user experience might help us understand better.

    Best I can tell, after a user selects a state, all queries run for that user will be restricted to that selected state. If that selection should only persist for a session, the selection can be passed as an URL parameter. If the selection should persist for multiple sessions, cookies are a good option if users are not always logged in. If they are logged in, their selection could be saved in user meta. Storage only in user meta can be used to encourage visitors to register to avoid reselecting on every visit. Then their selection persists even when they use different computers or browsers.

    You can use setcookie() to store values in the user’s browser, but it can only be used when headers are sent. The values stored are then in $_COOKIE on every request from that browser. If setting cookies with headers is too constrictive, use javascript or jQuery, which can be done at any time during the session.

    Thread Starter fredperes

    (@fredperes)

    Thanks, bcworks!
    Here’s what I want to achieve:

    . In home page I have projects (custom post type) and professionals (custom post type).
    . I would organize the 2 custom post types by states.
    . The user could filter the content by states (Michigan, for example). When he chooses Michigan, the home page reloads (or some ajax reloading), and displays only projects and professionals for that state.

    The question is:

    The user navigates in other pages that show the projects and the professionals. I need to ‘remember’ the state that he chose in home page and displays only the projects and professionals based on the user selection.

    A programmer told me to use sessions. Session are stored on the server and follow the user during its navigation. The user can’t update values in its browser, it’s a PHP private feature.

    Is there a plugin for that? Or should I code by myself?

    Moderator bcworkz

    (@bcworkz)

    Thanks for the explanation, that is what I thought, but some doubt lingered.

    Session data is a good alternative to passing data via URLs. The drawback is the data does not persist too long. The user must again make a selection when he returns for a new session. For persistent data, your options are still either cookies or user meta.

    There may be a plugin to help with this, but this task is not all that complex, custom coding is certainly attainable without too much work.

    Once you decide how you will save the user choice, you can use the ‘pre_get_posts’ action to apply that choice to all queries for that user.

    josegettas

    (@josegettas)

    Hi, how are you fredperes?

    Could you solve this? How did you do it?

    I have to do the same thing. I need to filter my custom post types by a taxonomy, and need to remember that taxonomy while navegating the hole website.

    Can you help me?

    Thanks!

    José

    Thread Starter fredperes

    (@fredperes)

    José,

    I hired a back-end developer to solve this. He did it in 30 minutes…

    josegettas

    (@josegettas)

    Can you send me his contact?

    Thanks!

    Thread Starter fredperes

    (@fredperes)

    Send me your email to contato[at]fredperes.net

    josegettas

    (@josegettas)

    Done!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Filter content by taxonomy’ is closed to new replies.