Support

Account

Home Forums Backend Issues (wp-admin) Trouble querying posts with fields

Solving

Trouble querying posts with fields

  • I suspect it might be a conflict with having created identical fields multiple times with the same ‘slug’ during development, and that the values atributed to those fields might still be lurking in the database.
    In this case:
    If I export all my ACFs with your export tool, deactivate and uninstall the plugin, and reverse verything, will the leftover data disappear?
    Is there any good practice of cleaning up unwanted values during production?

    This is what is happening:
    I’m trying to list all my users and display their associated articles (CPT).
    in this code, the no user gets atheir proper articles…

    
    // shared articles have a user_list
    // proprietary articles have a single user
    // community articles have an associated CPT called Video, as a video_list
    
    $user_articles = get_posts(array(
      'numberposts'   => -1,
      'post_type'     => 'articles',
      'meta_query'    => array(
        'relation'      => 'OR',
        array(
          'key'       => 'user_list',
          'value'     => $user -> ID,
          'compare'   => 'IN',
        ),
        array(
          'key'       => 'user',
          'value'     => $user -> ID,
          'compare'   => '=',
        ),
        array(
          'key'       => 'video_list',
          'value'     => $user_videos_ids_array,
          'compare'   => 'IN',
        ),
      ),
    ));
    
    
  • No, the ACF export tool only exports the field definitions and has no effect on any data saved in those fields. The only way to fix this would be to find and remove all of the old data manually in the database, or use a new unique field name that has not been used before.

    Long discussion about this here https://support.advancedcustomfields.com/forums/topic/flush-unused-custom-fields/

  • @hube2 Can you please tell me if this is the way to use get_posts in order to get all the articles(CPT) where at least one of the IDs in $array_of_video_ids is of a video selected in video_list, which is a multiple values post type acf? I’m quite stuck.
    `
    array(
    ‘key’ => ‘video_list’,
    ‘value’ => $array_of_video_ids,
    ‘compare’ => ‘IN’,
    ),
    `
    If the post type field is single value, I can query it, but wether I’m trying to to match one ID or multiple, if the field allows multiple, I don’t know how to query.
    `
    array(
    ‘key’ => ‘video’,
    ‘value’ => $video -> ID,
    ‘compare’ => ‘IN’,
    ),
    `

    Thank you!!♥

  • I’m not sure what you mean.

    What type of ACF field is it, relationship, post object, something else?

    Have you changed the multiple setting since it was created so that the field might contain a single value or multiple values?

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Trouble querying posts with fields’ is closed to new replies.