Support » Plugin: Pods - Custom Content Types and Fields » Filtering posts by meta value which have value „0“

  • Resolved David


    Hi. I will be very grateful if you can help me.

    I created custom field „stone_branch“ for my custom post type. This custom field is Yes/No checkbox.

    I use special module of my theme to display posts on frontend. This module allows me to filter posts by custom meta value. I need that when I use filtering of posts it will show only these posts which have “Yes” (it means “1”) value in post meta field. And posts which have meta value “0” (checkbox is not checked) will not be displayed after filtering.

    But right now posts for which I didn’t check checkbox (have meta value “0”) are also displayed after filtering.

    Right now I can do it manually by creating new custom field “stone_branch” individually in wordpress for all posts for which I need to have “Yes” (meta value 1). And other posts which will not have created custom field “stone_branch” (will not have any value for such custom field) will not by visible after filtering. But when I use pods plugin to create custom field “stone_branch” for all posts, it automatically add value “0” when I dont’t check checkbox for this custom field.

    Is there any way how to not display posts with value “0” in meta field when I want to filter posts by value of meta field?

    I am not programmer so thank you for any advice, David

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Jim True


    What are you using to filter with? You didn’t explain that part, just ‘use special module of my theme to display posts’. It sounds like the issue might actually be in that module, but I can’t tell with knowing what that module is. Typically for “No” check we don’t write ANY value. It’s 0 or NULL.

    Hi. This module use Ajax for filtering posts.

    Yes I now that pods for “No” check add value 0.

    But anyway I have one more question.

    I changed previous Yes/No checkbox field type to Plain Text field type. Good thing with this field type is that when I don’t fill this field with any value, pods plugin doesn’t automatically add value 0 (null). So such meta field is empty. But the posts filter which I use shows as result of filtering all posts which have my custom meta field „stone_branch“ and it’s no matter if this meta field is empty or has some value.

    So I wonder, if there is a way how ensure that pods plugin will delete my custom meta field „stone_branch“ from posts if this stone_branch field is empty.

    It means that posts for which I add some value (text) in field stone_branch will be visible after filtering posts and posts for which I don’t add some value (text) in field stone_branch (this field will be empty) will be delete with pods plugin and such posts without meta field stone_branch will not be visible after filtering of posts.

    Is there a way how to create for example some condition which will delete empty meta field from posts?

    Thank you, David

    Plugin Author Jim True


    Custom meta is added for all of your posts regardless of whether there is data in the field or not. If you used the same name, you should revisit the fields to make sure they have an accurate value. Resaving the post with checked or unchecked should fix any where you had a text value before. Typically, it’s probably best to delete the field entirely and recreate a new field with a different name if you don’t want issues like the above cropping up.

    You can also do that with SQL deleting directly from wp_postmeta but that’s very destructive.

    Thank you very much for your response. But I am not sure if you understand me.

    Now, please, forget about my previous questions. I need to know, in general, if
    there is a way how to create for example some condition in code, which will delete empty meta field from posts?

    So when I not enter value to my custom field (will be empty), this custom field (or meta key from this custom filed – sorry I am not programmer so I am not sure in terminology) will be deleted from list of fields for this post.

    I can achieve it by doing it manual. I will create my custom filed only for these posts for which I will need. But I want to use pods plugin. I want to add my custom field for all posts and add some condition in code that delete only these meta fields for which I don’t enter any value.

    Is it somehow possible?

    Thank you, David

    Plugin Author Jim True


    Meta Fields as I indicated above exist for every post regardless if they have a value in them or not. If you’ve configured the meta field for that post type, it will _always_ exist for every post in that post type. If you delete the field, it will be deleted.

    You cannot do what are you suggesting (remove the custom field for posts that do not have the field ‘completed’ conditionally) because Pods registers custom meta/custom fields at the POST Level, not as a separate entity like ACF does. We are more geared towards keeping content types together, so we don’t have any kind of custom field registered on it’s own. You might be able to accomplish what you’re trying in ACF.

    Did that answer your question?

    Ok, thank you.

    Plugin Author Jim True


    You’re welcome 😉

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Filtering posts by meta value which have value „0“’ is closed to new replies.