0

我正在尝试为自定义帖子类型运行自定义循环,并通过一些过滤meta_keyvalue

现在简单的元值可以正常工作,但在这里我遇到了以下类型的序列化数据(嵌套)的挑战。

我正在将wpalchemy用于元框。帖子meta_key类型如下_event_metavalue

a:9:{s:19:"ac_event_operations";a:1:{i:0;s:8:"Training";}s:18:"ac_event_positions";a:1:{i:0;s:10:"Supervisor";}s:18:"ac_event_employees";a:1:{i:0;s:2:"15";}s:13:"ac_event_date";s:10:"2017-06-15";s:19:"ac_event_start_time";s:5:"06:30";s:17:"ac_event_end_time";s:5:"07:00";s:14:"ac_event_place";s:6:"Office";s:18:"ac_event_organizer";s:4:"Jack";s:16:"ac_event_contact";s:4:"Rose";}

我正在尝试All Events根据ac_event_operations, ac_event_positions,进行过滤ac_event_employees

所以对我来说,挑战是使用上面 meta_keys 的值过滤事件。这是我使用的查询,但当然,它没有给出任何结果。

global $event_mb;
$meta = get_post_meta( get_the_ID(), $event_mb->get_the_id(), TRUE );

$paged    = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args     = [
    'post_type'      => 'event',
    'posts_per_page' => get_option( 'posts_per_page' ),
    'paged'          => $paged,
    'meta_query'     => [
        'meta_key' => '_event_meta',
        'value'    => '%ac_event_employees%',
        'compare'  => 'LIKE'
    ],

];
$temp     = $wp_query;
$wp_query = NULL;
$wp_query = new WP_Query( $args );
4

1 回答 1

0

像下面这样使用,

$args = array(
    'meta_query' => array(
        'relation' => 'OR',
            array(
                'key'     => 'country',
                'value'   => 'Israel',
                'compare' => '='
            ),
            array(
                'key'     => 'age',
                'value'   => array( 20, 30 ),
                'type'    => 'numeric',
                'compare' => 'BETWEEN'
            )
    )
 );
$user_query = new WP_User_Query( $args );

更多参考:https ://codex.wordpress.org/Class_Reference/WP_User_Query

于 2017-06-12T10:38:34.007 回答