Search code examples
wordpressadvanced-custom-fieldscustom-post-type

Wordpress & ACF. Custom post type archive page post ID


I'm building a Wordpress website locally, also using version control.

I have a custom post type page called "Events". I've created an ACF field (wysiwyg) called "heading editor" that outputs on the custom post type archive page.

I'm currently passing in the page ID. ie "wp-admin/post.php?post=123&action=edit", as follows

$post_id = 123;
$header = get_field('heading_editor', $post_id);

The issue is, when this site is pushed to the development environment, the page ID for the custom post archive page is lively to change as the site on the dev environment hasn't been created yet as will likely conflict with the "123" page id for that template

Apart from setting this functionality in "Options". Is there anyway to do this dynamically?

I've tried numerous ways of getting the ID.

get_ID();
get_the_ID();
get_queried_object()

All return a different ids to the actual page template called "Event" ie 123


Solution

  • This might help, I remember doing something where I needed to do something like this and I used:

    get_page_by_path( 'path/page', 'OBJECT');