Creating custom query from form data
-
Hello, I’m trying to create a “compare” sort of function on a website I am building. I have a compare.php file that takes all posts from a custom post type and lists them inside a form with each post having a checkbox. What I’d like to do is make it so that when the user submits the form, a new page will load that will build a query using the ids from the posts that were checked off.
The basic outline of the code I wrote on the compare.php file is something like this.
<form id="compare-form" action="<?php bloginfo('url'); ?>/compare-results" method="get"> // query to get the custom post type is here // The loop includes a bunch of information then at the end a checkbox that makes the name equal the id for that post, like this: <input type="checkbox" name="<?php echo get_the_ID(); ?>" value=""> <input type="submit" id="searchsubmit" value="Compare" /> </form>
I then have built a compare results template that has a custom query using these args, but I can’t figure out how to get the post ids from the previous page into this query.
$args = array( 'post_type' => 'customposttype', 'post__in' => array( how do I get the post ids from the checked boxes into this array?? ) );
I hope this make sense. In the end it should build a query using only the posts that were checked off on the previous page.
- The topic ‘Creating custom query from form data’ is closed to new replies.