Z
Z
Zhandev2016-03-28 15:04:16
MySQL
Zhandev, 2016-03-28 15:04:16

How to select meta fields in wordpress?

How to select meta fields in wordpress?
There is a meta field "close_date", you need to make a selection for those posts where the field "close_date" has any value.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
Ivan Kozlov, 2016-03-29
@Zhandev

$query = new WP_Query( array(
    'meta_query' => array(
        array(
      'key'     => 'close_date',
      'value'   => '',
      'compare' => '!=',
  ),
     )
) );

Try this

N
nozzy, 2016-03-29
@nozzy

global $wpdb;
  
$qry = "select  t1.*
    from wp_posts t1
    inner join
    (
      select 
      post_id
      from wp_postmeta
      where meta_key = 'close_date' and meta_value = '2016-03-29' 
    ) t2 on t2.post_id = t1.ID";

$rows = $wpdb->get_results( $qry );

foreach( $rows as $row ) {
  ...
}

V
Vladyslav Phenychnyi, 2016-03-28
@IT-means-lucky

Check out this little post

Z
Zhandev, 2016-03-28
@Zhandev

The field stores the date

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question