在query_posts()中合并tax_query和meta_query

时间:2017-04-13 00:14:11

标签: php wordpress

我尝试获取具有预定义元值的自定义帖子。查询不返回任何内容。

    $args = array
    (
        'post_type' => 'item',
        'nopaging' => true,
        'tax_query' => array
        (   array
            (
            'taxonomy' => $taxonomy,
            'field' => 'term_taxonomy_id',
            'terms' => $term_id
            )
        ),
        'meta_query'  => array(
            array(         
                'key'     => 'from_import',  
                'value'   => '1', 
            )
        )
    );
    $posts = query_posts( $args );

当我删除meta_query或tax_query时,它可以正常工作。我怎么能把它结合起来?

2 个答案:

答案 0 :(得分:0)

我应该修复你的代码。我还没有实际运行它,但试试看。你有一个额外的'数组()'在他们每个人。

17/04/13 00:53:34 WARN org.apache.spark.scheduler.TaskSetManager: Lost task 0.1 in stage 0.0 (TID 1, lol-w-0.c.sunlit-aura-164219.internal): 

java.sql.SQLException: Value '17422532167853
    2151-08-040000-00-00 00:00:000000-00-00 00:00:00Discharge summaryReport00�yAdmission Date:  [**2151-7-16**]       Discharge Date:  [**2151-8-4**]


Service:
ADDENDUM:

RADIOLOGIC STUDIES:  Radiologic studies also included a chest
CT, which confirmed cavitary lesions in the left lung apex
consistent with infectious process/tuberculosis.  This also
moderate-sized left pleural effusion.

HEAD CT:  Head CT showed no intracranial hemorrhage or mass
effect, but old infarction consistent with past medical
history.

ABDOMINAL CT:  Abdominal CT showed lesions of
T10 and sacrum most likely secondary to osteoporosis. These can
be followed by repeat imaging as an outpatient.



                            [**First Name8 (NamePattern2) **] [**First Name4 (NamePattern1) 1775**] [**Last Name (NamePattern1) **], M.D.  [**MD Number(1) 1776**]

Dictated By:[**Hospital 1807**]
MEDQUIST36

D:  [**2151-8-5**]  12:11
T:  [**2151-8-5**]  12:21
JOB#:  [**Job Number 1808**]
                                   ' can not be represented as java.sql.Timestamp

答案 1 :(得分:0)

我刚刚完成了这个,这是我用于我的方案的工作片段,根据需要进行调整以满足您的需求。

// Bring post from the global context (if not present already).
global $post;

// Define the post_type's to query for.
$post_types = array( 'event', 'post', 'book' );

// Do the weird query. 
// Play with, or add arguments as needed https://codex.wordpress.org/Class_Reference/WP_Query
$results = WP_Query(
        array(
            'post_type' => $post_types,
            'tax_query' => array(
                array(
                    'taxonomy' => 'category',
                    'terms' => wp_get_post_categories( $post->ID )
                )
            ),
            'meta_query' => array(
                'relation' => 'OR',
                array(
                    'key'     => 'presenters_people',
                    'value'   => $post->ID,
                    'compare' => 'LIKE'
                ),
                array(
                    'key'     => 'author',
                    'value'   => $post->ID,
                    'compare' => 'LIKE'
                )
            )
        )
    );