【发布时间】:2014-09-22 19:08:13
【问题描述】:
好的,我正在努力解决这个问题。我的问题归结为按元值和类别查询帖子,我似乎无法让它输出任何内容。
我已经完成了WP_Query(); 路由,并转储了我的变量,并且表单返回了这些变量中应该返回的所有内容,但它没有从数据库中提取任何帖子。我没有得到任何结果。代码如下。
<h1>Product Selector</h1>
<?php
if ( !$_POST['submit'] ) : ?>
<form method="post">
<br><strong>Category:</strong><br>
<?php wp_dropdown_categories(array(
'show_option_all' => 'Please Choose',
)); ?>
<br><br><strong>Adhesion:</strong><br>
<select id="adhesion" name="adhesion">
<option></option>
</select>
<!--<br><br><strong>Substrate:</strong><br>
<select id="substrate" name="substrate">
<option></option>
</select>-->
<br><br>
<input type="submit" name="submit" value="submit">
</form>
<?php
else :
$ca = $_POST['cat'];
$ad = array( 'key' => 'adhesion_box', 'value' => $_POST['adhesion'] );
$su = array( 'key' => 'substrate_box', 'value' => $_POST['substrate'] );
$args = array(
'post_type' => 'post',
'meta_query' => array($ad),
'cat' => $ca,
);
var_dump($args);
$myQuery = new WP_Query( $args ); ?>
<?php
if ( $myQuery->have_posts() ) :
echo "<ul>";
while ($myQuery->have_posts()) :
$myQuery->the_post(); ?>
<li><a href="<?php the_permalink(); ?>">
<?php the_title(); ?></a>
</li>
<?php endwhile;
echo "</ul>";
else : ?>
<h3>Sorry, no products matched the details you entered.</h3>
<form method="post">
<br><br><strong>Category:</strong><br>
<?php wp_dropdown_categories(array(
'show_option_all' => 'Please Choose',
)); ?>
<br><br><strong>Adhesion:</strong><br>
<select id="adhesion" name="adhesion">
<option></option>
</select>
<!--<br><br><strong>Substrate:</strong><br>
<select id="substrate" name="substrate">
<option></option>
</select>
<br><br>-->
<br><br>
<input type="submit" name="submit" value="submit">
</form>
<?php
endif;
endif; ?>
不,它不需要类别模板或类似的东西,因为我没有在循环中包含该调用,并且 WordPress 仅在您这样做时才调用模板文件。击掌。
我在像这样的其他页面上使用自定义循环,但出于某种原因,这个只是没有返回任何帖子,我无法弄清楚。
进入产品,找到一个特定的产品,任何你想要的,然后在表格中输入它的规格(这样你就知道你有一个应该返回的特定产品),然后看着......什么都没有发生...... ..
我的查询有什么问题?我想不通。
相关链接
【问题讨论】:
-
你如何在服务器端访问这些值?尝试打印 $_REQUEST 并检查
-
@Remy Sheppard 你能告诉粘附是序列化对象还是整数?您是否可以发布一些具有结构的示例数据
-
这个问题具有误导性,因为 OP 正在寻找从数据库中检索
meta_value的查询,而他正在向社区询问其他内容:current query isn't returning any result。
标签: javascript php jquery wordpress forms