Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to get posts which geo_latitude and geo_longitude meta values are existed (or not null, not blank value)

so basically, select * from posts where geo_latitude<>'' and geo_longitude<>'' I have been doing like this but I can't really get them.

How can I get these meta condition clause?

 $args = array(
    //'offset'              =>0,
    'orderby'          => 'post_date',
    'order'             => 'DESC',
    'post_type'        => 'custom_post_type',
    'post_status'      => 'publish',
     'tax_query' => array(
        array(
         'taxonomy' => 'tax_type',
         'field' => 'id',
         'terms' => $catArr
        )
        ),

    //'meta_key=Date&meta_compare=>=&meta_value=_TODAYS_DATE_HERE_'

    'posts_per_page' => '150'
    );

    $marker = array();

    $query1 = new WP_Query( $args );
           while ( $query1->have_posts() ) : $query1->the_post();
                                    ''''''''''''''''

short question, It works fine now but I just want to make sure.

    'tax_query' => array(
        array(
         'taxonomy' => 'tax_type',
         'field' => 'id',
         'terms' => $catArr
        )
        ),

For this array, I actually need to put IF condition before 'tax_query' starts. if ($catArr) .....

Because I don't need to compare if there is not $catArr. it just need when there is $catArr.

it's working now but I need to know if it's right or not.

Thanks,

This is the meta query..

         meta_query' => array(
        'relation' => 'OR',
            array(
                'key' => '_geo_latitude',
                // 'value' => 'foo',
                // 'compare' => 'LIKE',
            ),
            array(
                'key' => '_geo_longitude',
            )
    ),

But it gets wrong result. I need to get if there are values for _geo_latitude, _geo_longitude.

share|improve this question
    
Hmm, you don't have any meta query in your code (it's commented). Is the commented part the code that you have tried? –  Krzysiek Dróżdż Nov 25 '13 at 8:35
    
yes I tried, I just added the bottom of page. but it's not working properly. did I miss anything? –  pulla Nov 25 '13 at 9:45
    
I guess, you missed PHP tutorial and WP_Query Codex page ;) Could you tidy up your question a little bit? After your last edit I can't really get what are you trying to achieve and what's your exact problem... You shouldn't post here any redundant code, and if parts of your code are commented, then it's hard to say if you want them or not. –  Krzysiek Dróżdż Nov 25 '13 at 10:07
    
Please follow up on the questions you asked, it's an important part of the process on WPSE - see What should I do when someone answers my question? and Why is voting important? for a deeper insight. Thank you! –  ialocin Nov 27 '13 at 22:08

1 Answer 1

up vote 1 down vote accepted

Regarding your first problem, because $args is an PHP: array you could do something like this:

Code:

$args = array(
    'orderby'          => 'post_date',
    'order'             => 'DESC',
    'post_type'        => 'custom_post_type',
    'post_status'      => 'publish',
    'posts_per_page' => '150'
);

if ( $catArr ) {
    $args['tax_query'] = array(
      array(
        'taxonomy' => 'tax_type',
        'field' => 'id',
        'terms' => $catArr
      )
    );
}

Note: code is exemplary

Regarding your second question, regarding the meta_query, you should take a look at this:

share|improve this answer
    
it gets an error. I can't really see the error message. cuz ajax page. I tried to find the error on page of the source and get blank. –  pulla Nov 28 '13 at 7:11
    
I fixed a typo @pulla –  ialocin Nov 28 '13 at 10:46
    
thanks it works great!! –  pulla Nov 29 '13 at 5:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.