Support

Account

Home Forums General Issues Displaying correct postID content on blog page (home.php) Reply To: Displaying correct postID content on blog page (home.php)

  • I just did a quick look and I found this at the beginning of the ACF code that determines the current post ID

    
    $preload = apply_filters( "acf/pre_load_post_id", null, $post_id );
    

    This can be used to determine the post ID, if you return any value it will override ACF looking for the post ID.

    I do not know the specifics of what you need to do off the top of my head… and it could get complicated and there are a number of factors to consider.

    Just as a for instance, you would want to return the value for get_option( 'page_for_posts' ); only if you were not inside the main loop and you actually want to show a field for the current post. I’m not exactly sure without doing a lot of testing how to determine this.

    this might work, but it is only a guess

    
    add_filter('acf/pre_load_post_id', 'your_filter_name_here', 10, 2);
    function your_filter_name_here($value, $post_id) {
      $queried_object = get_queried_object();
      // queried object will be page for posts if it is the blog page
      if (is_a($queried_object, 'WP_Post') && $queried_object->ID == get_option(page_for_posts')) {
        $value = intval(get_option(page_for_posts'));
      }
      return $value;
    }
    

    There is also a filter at the end of the ACF code to determine the post ID that can potentially also be used in some way.

    
    $post_id = apply_filters('acf/validate_post_id', $post_id, $_post_id);