Comparison operator

I've build a dropdown box with a list of comparison strings.

array(
        'value' = array(
            __( 'Equal', 'js_composer' ) = '=',
            __( 'Does not equal', 'js_composer' ) = '!=',
            __( 'Greater than', 'js_composer' ) = '',
            __( 'Greater than or equal to', 'js_composer' ) = '=',                    
            __( 'LIKE', 'js_composer' ) = 'LIKE',
            __( 'NOT LIKE', 'js_composer' ) = 'NOT LIKE',
            __( 'IN', 'js_composer' ) = 'IN',
            // ...etc.
        ),          
    ),  

        if( $meta_query_value !== '' ) {
            $args['meta_query'][] = array(
                'key'     = $mp_metakey,
                'compare' = $mp_comparison, 
                //'compare' = '=',
                //'compare' = esc_attr( $mp_comparison ), 
                'value' = $value,
        );
      } 

I did a var_dump ($mp_compare); which showed string(5) "="

And yet no posts are being displayed. When I use 'compare' = '=', directly, posts do show up.

I did noticed that when I use 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'EXISTS posts are showing up.

But when I select the usual operators '=', '!=', '>', '>=', '', '=' it's doesn't work.

I also tried using 'compare' = esc_attr( $mp_comparison ), but that doesn't work either.

Anyone an idea?

Topic comparison Wordpress

Category Web


string(5) ">=" concerns me. It should be string(2) should it not? This feels like you're actually getting &gt;= instead of >=. If you are doing a var_dump into the basic HTML body, it will encode what you see. View Source or wrap your var_dump in a <pre> tag, and you should see what's up.

Try doing html_entity_decode($mp_compare) and see what you get :).

(Moving this to an answer so you can close the question).

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.