Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Custom Post Type Does Not Appear In Query Parameter

  • There are actually two issues that are probably related.

    I was working with Conditions. At first it was going great, then suddenly problems appeared. For background:

    1. A custom post type called “Placements” was created with ACF.
    2. The CPT has field groups.
    3. One of the fields has an optional image.
    4. The condition: If the image is present, use one container. If the image is not present, another container is used. The formatting in each container is different.

    It became apparent that only one container block was used even though the test data had two records, one for each condition. This would indicate an issue with the conditions. This was odd because it was working earlier.

    See image 1a and 1b for how the conditions are being tested.

    I then ran an SQL query to verify the value of this image field, that is, to verify it is null. See the image 2a and 2b for the results of that query.

    Seeing that the data exists, I worked backward to the GB query block. In looking at the query block, it seems that the custom post type disappeared from the selection on the query parameter. See images 3 attached. There is another CPT that was created that does appear (called landing pages), but the one I was working with does not appear.

    Next the following was performed:

    • The permalinks were flushed.
    • A one-time PHP snippet to register the post type as publicly available (see image 4).
    • The permalinks were flushed again.

    Nothing worked. The post type still does not appear in the query block parameter.

    Have you seen this before? Any idea what I could try? I’m out of ideas.

    Thanks for any assistance.

  • Hi there,

    Can you provide an admin login to your site so we can see the full picture of the setup?

    And please link us to an example custom post for the image condition issue.

  • All the creds are in the “Private Information” below, including the link.

    In the list view of the page, to get to the query loop click down through the named containers as shown:

    Placements Section
      Placements Loop
        Query loop
          Grid
            Post Template
              Top Half
                Headshot Missing
                Headshot Present

    The conditions are in the last two containers in the stack (Headshot Missing, Headshot Present).

    The post type I am trying to query is “placement”.

  • Hi there,

    Regarding the Post Meta condition — there’s currently a known bug in the system. The existing exists and not_exists operators only check whether a key is present, but they can’t distinguish between:

    – A field that exists but is empty (”)
    – A field that exists with a value (e.g. ‘content’)
    – A field with a value of zero (0 or ‘0’), which is still valid

    If it’s not working as expected, it’s likely due to this issue. We already have a fix in place, which will be included in the next GB Pro release.

    As for the post type not appearing under the Query Loop block settings — go to ACF > Post Types, edit your Placements post type, then open the Advanced Configuration section. Under the URL settings, enable the Publicly Queryable option: https://cln.sh/7Jf8LB6PRV6ZccHXKsyP

    Once that’s done, the Placement post type should appear in the list.

  • Thank you for the Post Type direction. I flipped it, and it worked.

    Do we have a target date for a release of the fix? I need to know if we should wait or if it is too long I’ll need to look for another 3rd party plug-in that facilitates this conditional formatting.

  • Can you try this PHP code? The code forces ACF to remove the field data if it’s empty when the post/page is saved.

    add_action('acf/save_post', function( $post_id ) {
    
        // Skip ACF options pages or other non-post objects
        if ( ! is_numeric( $post_id ) ) {
            return;
        }
    
        // Get all ACF fields for this post
        $fields = get_field_objects( $post_id );
    
        // If no fields, stop
        if ( empty( $fields ) || ! is_array( $fields ) ) {
            return;
        }
    
        foreach ( $fields as $field_key => $field ) {
            $name  = $field['name'];
            $value = get_field( $name, $post_id, false );
    
            // If the value is empty (null, '', [], etc.)
            if ( empty( $value ) && $value !== '0' ) {
                delete_post_meta( $post_id, $name );
            }
        }
    });

    Let me know if this helps!

  • That worked! I added it via the Code Snippets plug-in with the description to remove or suspend it when GB Pro 2.4.1 is released.

    I was a little nervous about altering the behavior of ACF, thinking there might be a reason for it to be the way it is. To check to make sure the code posted from YING earlier is safe, I triangulated her approach with AI. Fascinating result. It not only validates what she posted, but also seems to know that the proper fix would be in the query. I’m posting it here for grins:

    # # #
    The Prompt:
    Background: The context is WordPress internals. A post type and field groups were created by ACF. One of the fields are optional. If the user does not populate it when creating the post, the key/value for that post/field is created in the database without a value. Would deleting that key/value with the delete_post_meta function create problems? It seems like if the post/key was created without a value, it should be that way for a reason.

    Claude answers:
    You’re right to be cautious! In the context of ACF (Advanced Custom Fields), here’s what’s happening and whether it’s safe to delete:

    What ACF is doing:
    When ACF creates a field entry in wp_postmeta without a value, it’s typically storing an empty string (”) as the value. ACF does this to indicate that:

    The field exists and has been “touched” or saved at least once
    The field is intentionally empty (user left it blank)
    It helps ACF distinguish between “field was saved as empty” vs “field has never been saved”

    Is it safe to delete?
    Generally yes, but with caveats:

    Deleting won’t break ACF – ACF will continue to work fine
    The field will reappear as empty – If the post is edited again and saved, ACF will recreate the empty meta entry
    You might lose the “has been set” state – ACF may treat it as “never saved” rather than “intentionally left blank”

    When you might want to delete:
    Database cleanup – Removing unnecessary empty entries to reduce database bloat
    Conditional logic – You want to check if a field exists vs. is empty
    Performance – On sites with many posts and fields, empty meta can add up

    When you should NOT delete:
    If ACF conditional logic depends on it – Some ACF setups check for field existence
    If custom code checks for the meta key – Your theme/plugins might use metadata_exists() or similar checks
    If you’re using ACF field groups with location rules – ACF uses these entries to track which fields belong to which posts

    Better approach:
    Instead of deleting, consider querying to exclude posts where the field is empty:

    php
    $args = array(
        'post_type' => 'your_post_type',
        'meta_query' => array(
            array(
                'key' => 'your_field_name',
                'value' => '',
                'compare' => '!='
            )
        )
    );

    # # #

  • Great, you found your solution 🙂

  • You gave me the solution, Ying. I just validated it with Claude.ai. Thank you!

  • You are welcome   🙂

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.