0

I am trying to get post of custom post type by two meta value but it does not work. I have followed lots of article but not worked below are my code.

Note: 1. first meta value is a type of date eg: '17/12/1976' 2. second meta value is a type of text eg: 'E20001011'

$rollnum = $_POST['rollnum'];
$studentdob = $_POST['studentdob'];

<form class="advanced-search-form" method="post">
   <div class="form-group">
    <label>Student Roll NO.</label>
    <input type="text" name="rollnum" value="<?php echo esc_attr( $rollnum ); ?>">
   </div>
   <div class="form-group">
    <label>Student date of birth</label>
    <input type="text" name="studentdob" value="<?php echo esc_attr( $studentdob ); ?>" placeholder="dd/mm/yyyy">
   </div>
   <div class="form-group">
     <input type="submit" value="Search" style="font-size:18px">
   </div>
</form>             

<?php
if ( $rollnum && $studentdob ): ?>
    <div class="search-result">
     <?php
      $args = array(
        'post_type'  => 'student_results',
        'meta_query' => array(
           array(
             'key'     => 'student_date_of_birth',
             'value'   => $studentdob,
           ),
           array(
             'key'     => 'student_roll_no',
             'value'   => $rollnum,
          ),
        ),
     );           
     $search_query = new WP_Query( $args );

    if ( $search_query->have_posts()):
        while ( $search_query->have_posts() ) {
            $search_query->the_post();
            get_template_part( 'template-parts/content', 'result' );
        }
        wp_reset_postdata();
    ?>
     <?php else: ?>
     <p>No result found.</p>
     <?php endif; ?>
     </div>
    <?php endif; ?>

get_template_part from the file is "template-parts/content-result.php" and code is given below

<article>
<div class="blog-lists">
    <div class="entry-content">
            <?php
            the_title();
            the_content();      
            ?>
    </div>
</div>  
</article>
  • What do you mean by "does not work"? Nothing being displayed? WSOD? What does template-parts/content/result.php contain? – leymannx Apr 10 '19 at 21:56
  • Is the form in the same file as the query? – Howard E Apr 10 '19 at 23:19
  • What is the content of your $search_query? – moped Apr 11 '19 at 6:17
  • Hi @leymannx, Yes its nothing being displayed and also I have edited my question and given my included template part code please have a look and let me know what did I do wrong? – Yajuvendra pratap singh Apr 11 '19 at 9:10
  • Hi @HowardE, I have edited my question and provided my whole code of file please have a look – Yajuvendra pratap singh Apr 11 '19 at 9:15
0

I did by removing backslash(/) from Date.

$resultdob = $_POST['studentdob'];
$studentdob = str_replace("/", "", $resultdob);
| improve this answer | |
  • That's a slash. – leymannx Apr 11 '19 at 15:54

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.