0

I'm doing a small project and I'm stuck and really hoping for your help. The problem is, I would like to have the user type in a code and the form do a double check, 1 if it exists as a value 2 which category it belongs to. Then as an answer will be a different div for each category. Thank you all!!!

https://mzf73.wineqrcode.com/gioco-con-i-codici/

 <style type="text/css">
        p {
        float: left;
        margin: 5px;
        }
        
        </style>
        
        
        <?php
        /* Template Name: Gioco con i numeri */
        
        // Resetto la query se necessario
        //wp_reset_postdata();
        
        /** 
         * Preparo gli argomenti
         *
         * Possibili parametri:
         * 'orderby'                => 'title',
         * 'order'                  => 'ASC',
         * 'posts_per_page'         => 3,
         * 'category_name'          => 'featured',
         * 'cat'                    => -1 //esclude una categoria o pi첫 categorie dalla query
         */
        $args = array(
            'post_type' => 'wine_code',
            'order' => 'ASC',
            'posts_per_page' => -1,
        );
        
        
        // Eseguo la query
        $the_query = new WP_Query($args);
        
        // Conto gli elementi
        $count = $the_query->post_count;
        
        $output= (isset($_POST['submit']))?$_POST['input']:'';
        
        
        ?>
        
        
        <div style="padding-top:100px; width:50%; margin:auto;">
            
            <br>Enter the code shown on the bottle <br>
            
            <form method="post">
                <input type="text" name="input"/> <!-- thiss is where the user enters text -->
                <input type="submit" name="submit" value="submit"> 
            </form>
            
            <br><br>
            
        <?php
        
        $categories = get_categories(); $count = count($categories);
            foreach ($categories as $category) {
                echo '<p><b>' . $category->name . '</b></p><br><br>';
            }
        
        ?>
        
        <?php if ($the_query->have_posts()): ?>
                
                <?php while ($the_query->have_posts()): $the_query->the_post(); ?>
                
                <?php the_content(); ?>
            
                <?php endwhile; ?>
            
        <?php endif; ?>
        
        <?php
        
        
        
        $first_query = new WP_Query( $args );
            while ($first_query->have_posts()) : $first_query->the_post();
                //the_title();  //echo the title
                //the_content();         //echo the content
                        $str = get_the_content(); 
                        $choices = explode("-",$str);
                        //var_dump($choices);
                        
        
                    //foreach($choices as $key => $value){
                       // echo '<p>' . $value . '</p>';}
                    
                    if (in_array($output, $choices)) {
                                echo '<p> You have found the bottle of the year 2014 </p>';
                            }
            endwhile;
            
        
        ?>
        
        
        </div>
        
        <?php get_footer(); ?>
New contributor
bastiag5 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

bastiag5 is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.