admin管理员组

文章数量:1301514

General View I am creating a plugin which imports a csv file and using a shortcode i created a form that can search values from the uploaded csv file in sqlData base. Form have Three Input fields

  1. Search by Date(Using a date picker)
  2. Search by Name(text type)
  3. Search by Text (text Type)

Problem: I am Getting the right data by using both of the text Field but The Date picker isnt getting any match.

HTML Form

 <h1>Find Your Brick</h1>
<form action="" method="post">
<!-- Purchase Date -->
<label for="">
<h5 style="display:inline;margin-left:2rem">Search By Purchase Date</h5>
<input type="date"  name="purchase_date"> 
 </label>
<br>
<br>
<label for="">
<h5 style="display:inline;margin-left:2rem ; margin-right:1rem">Donor Name</h5>
<input type="text" id="textInput" placeholder="Search Here..." name="donor_name" >
</label>
<br>
<br>
   <label for="">
<h5 style="display:inline;margin-left:2rem ; margin-right:1rem">Brick Text</h5>
<input type="text" id="textInput1" placeholder="Search Here..." name="brick_text" >
</label>
  <input type="submit" name="submit" value="SUBMIT" style="margin-left:5rem">      </form>

Meta query This is my meta query

if (isset($_POST['submit'])) {

    $brick_text = $_POST['brick_text']; //Brick Taste
    $donor_name = $_POST['donor_name']; //Donor Name
    $purchase_date = $_POST['purchase_date']; //Date of Purchase

    $newDate = date("d/m/y", strtotime($purchase_date));
    $args = array(

        'post_type' => 'brick',
        'posts_per_page' => -1,
        'meta_query' => array(

             array(
                'key' => 'donor_name',
                'value' => $donor_name,
                'compare' => 'LIKE',
             ),
            array(
                'key' => 'purchase_date',
                'value' => $newDate,
                'compare' => 'LIKE',
            ),
             array(
                 'key' => 'brick_text',
                 'value' => $brick_text,
                 'compare' => 'LIKE',
             ),
        ),
        'orderby' => 'meta_value',
        'order' => 'ASC',
    );

}

What I have Tried

I have tried using the the php date function to convert the format of date of the date picker i'm using in the form Your Help will be really appreciated

本文标签: pluginsUsing metaquery to get date type values from postmeta table WordPress