Skip Navigation

[Resolved] Default value of single line field

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 1 year, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#2506063
Screenshot 2022-11-29 at 6.13.57 PM.png

Dear Sir/Madam,

I have a custom field in single line type, I try to query all fields without content

    $args = array (
    		'posts_per_page' => -1,
        'post_type'  => 'member',
        'post_status' => 'publish',
        'meta_query' => array(
            array(
                'key' => 'wpcf-uprise-payment-source-id',
                'value' => '',
                'compare' => '='
            )
        )
    );

but no result until I click into the post and publish without any change. Please advise how I can make the query args ?

#2506459

Hello,

For those existed posts, which don't have custom field meta values, you need to use "NOT EXISTS" operator, please try to modify your custom codes as below:

$args = array (
    'posts_per_page' => -1,
    'post_type'  => 'member',
    'post_status' => 'publish',
    'meta_query' => array(
        'relation' => 'OR',
        array(
            'key' => 'wpcf-uprise-payment-source-id',
            'value' => '',
            'compare' => '='
        ),
        array(
            'key' => 'wpcf-uprise-payment-source-id',
            'compare' => 'NOT EXISTS'
        )
    )
);

And test again

More help:
https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters

#2507847

Got your mean, will test and confirm

#2507913

OK, please update here if you still need more assistance for it.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.