简体   繁体   English

Wordpress Pod:在布尔字段上查找

[英]Wordpress Pods: Find on Boolean Field

I have a simple pod with a boolean called featured. 我有一个简单的Pod,带有一个名为特征的布尔值。 I'm trying to use the find() method (using the pods() shortcut) to list all pod entries that have the featured boolean set to true on a page template but I can't get it to work. 我正在尝试使用find()方法(使用pods()快捷方式)列出所有在模板模板上将具有布尔值设置为true的pod条目,但是我无法使其正常工作。 I found this answer but it's for the older version and doesn't seem to work in Pods 2.0. 我找到了这个答案,但这是针对旧版本的,似乎在Pods 2.0中不起作用。 If there's a simpler way to do this please inform me what I'm trying something like this: 如果有更简单的方法可以执行此操作,请告知我我正在尝试以下操作:

$params = array(
    'orderby' => 'date DESC',
    'where' => 'case_study.has_page = 1',
    'limit' => -1
);
$pods = pods( 'case-study', $params );

The error I receive is: 我收到的错误是:

WordPress database error: [Unknown column 'case_study.has_page' in 'where clause']
SELECT DISTINCT 't'.* FROM 'wp_posts' AS 't' LEFT JOIN 'wp_postmeta' AS 'case_study' ON 'case_study'.'meta_key' = 'case_study' AND 'case_study'.'post_id' = 't'.'id' WHERE 'case_study'.'has_page' = 1 AND 't'.'post_type' = "case_study" ORDER BY 't'.'date' DESC, 't'.'menu_order', 't'.'post_title', 't'.'post_date'

Database Error; SQL: SELECT DISTINCT 't'.* FROM 'wp_posts' AS 't' LEFT JOIN 'wp_postmeta' AS 'case_study' ON 'case_study'.'meta_key' = 'case_study' AND 'case_study'.'post_id' = 't'.'id' WHERE 'case_study'.'has_page' = 1 AND 't'.'post_type' = "case_study" ORDER BY 't'.'date' DESC, 't'.'menu_order', 't'.'post_title', 't'.'post_date'; Response: Unknown column 'case_study.has_page' in 'where clause'

It appears that it's not JOINing/WHEREing to the wp_postmeta correctlyy but I can't quite figure out how to use the find params to do so. 看来这不是正确地将wp_postmeta联接/定位到wp_postmeta ,但是我还不太清楚如何使用find参数来执行此操作。 It should should be 'case_study'.'meta_key'='has_page' amongst other problems. 除其他问题外,它应为'case_study'.'meta_key'='has_page' I've tried making the field a simple relationship with a Yes/No option but still no luck. 我尝试过使用“是/否”选项使该字段成为简单的关系,但仍然没有运气。

Thank you for any help you can provide! 感谢您提供任何帮助! It's much appreciated. 非常感谢。

如果您的关系字段名为“ has_page”,并且是简单的(自定义),则需要使用以下代码:

has_field.meta_value = 1

Found it! 找到了! When editing the pod I went to the 'Advanced' settings tab and under 'Capability Type' I set it to 'Custom' from 'Posts.' 编辑广告连播时,我转到“高级”设置选项卡,在“功能类型”下,将其从“帖子”设置为“自定义”。 Voila, it now works! 瞧,现在可以了! I suppose this setting tells the find calls how to operate on the tables. 我想这个设置告诉find调用如何在表上进行操作。 My final find params were as follows: 我最后找到的参数如下:

$params = array(
    'orderby' => 'date DESC',
    'where' => 'has_page.meta_value = 1',
    'limit'   => -1
);
$casestudies = pods( 'case_study', $params );

Thank you so much Scott for being quick and an awesome help! 非常感谢Scott的迅速和出色的帮助!

Final solution: 最终解决方案:

My original content type was an extension of post which doesn't seem to play well with relationship fields, at least basic ones, since it appears to assume they generate their own table which they don't always do. 我最初的内容类型是post的扩展,它似乎不适用于关系字段,至少是基本字段,因为它似乎假定它们生成了自己的表,但并不总是这样做。 As in this case where, since it was a simple custom relationship, the data was all stored in the wp_postmeta table. 在这种情况下,由于这是一个简单的自定义关系,因此数据全部存储在wp_postmeta表中。

The best solution I found was to rebuild my pod as an Advanced Content Type. 我发现最好的解决方案是将吊舱重建为高级内容类型。 This way, the pod generates a table all to its own so checking booleans can be done with a simple 'where' => 'has_page' = 1 instead of all the relationship complexity. 这样,pod会自己生成一张表,因此可以使用简单的'where' => 'has_page' = 1而不是所有关系复杂性来检查布尔值。 Thanks for all your help Scott. 感谢您的所有帮助,斯科特。

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

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