简体   繁体   English

按日期输入类型的WordPress查询帖子

[英]WordPress query posts by date input type

I am trying to display certain posts of a certain date that users can pick via a html date input type. 我正在尝试显示用户可以通过html日期输入类型选择的特定日期的特定帖子。

This is my date input in my html: 这是我在html中输入的日期:

<form name="form" action="" method="get">
    <input type="date" name="date" id="date" />
</form>

And I am trying to get the value like this: 我正在尝试获得这样的价值:

$date = $_GET['date'];
echo $date;

But I get this error: 但是我得到这个错误:

Undefined index: date 未定义索引:日期

Anyone has any idea how I can get the selected date? 任何人都知道如何获取所选日期? I am guessing the form still needs to be submitted, is there any way I can auto submit after selecting a date? 我猜仍然需要提交表单,选择日期后有什么方法可以自动提交? Preferably without using JS. 最好不使用JS。 Many thanks in advance! 提前谢谢了!

How you will get date parameter by submit button or using jquery 如何通过提交按钮或使用jQuery获取日期参数

i mean to say how the form is submitted without submit button 我的意思是说没有提交按钮如何提交表单

<form name="form" action="" method="get">
    <input type="date" name="date" id="date" />
</form>

You must check if the form's submited or not, example: 您必须检查表单是否已提交,例如:

if (isset($_GET['date'])) {
   $date = $_GET['date'];
} else {
   $date = date('d/m/Y');
}

You are probably trying to get the value of the date field before you have submitted the form. 您可能试图在提交表单之前获取日期字段的值。

Try the following: 请尝试以下操作:

if (isset($_GET['date'])) {
    $date = $_GET['date'];
    echo $date;
}

You can't make the form submit automatically without using some form of Javascript. 如果不使用某种形式的Javascript,就无法使表单自动提交。

For example: 例如:

<form name="form" action="" method="get">
    <input type="date" name="date" id="date" onchange="this.form.submit();" />
</form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM