ACF\CLI

JsonCommand::get_syncable_itemsprivateACF 6.8

Finds syncable items for a given item type using the same logic as the admin UI.

Method of the class: JsonCommand{}

No Hooks.

Returns

Array. Associative array of key => post data for syncable items.

Usage

// private - for code of main (parent) class only
$result = $this->get_syncable_items( $post_type );
$post_type(string) (required)
The item type.

Changelog

Since 6.8 Introduced.

JsonCommand::get_syncable_items() code ACF 6.8.8

private function get_syncable_items( $post_type ) {
	$syncable = array();
	$files    = acf_get_local_json_files( $post_type );

	if ( empty( $files ) ) {
		return $syncable;
	}

	$all_posts = acf_get_internal_post_type_posts( $post_type );

	foreach ( $all_posts as $post ) {
		$local    = acf_maybe_get( $post, 'local' );
		$modified = acf_maybe_get( $post, 'modified' );
		$private  = acf_maybe_get( $post, 'private' );

		if ( $private ) {
			continue;
		}

		if ( 'json' !== $local ) {
			continue;
		}

		// New item (not yet in database).
		if ( ! $post['ID'] ) {
			$syncable[ $post['key'] ] = $post;
			continue;
		}

		// Updated item (JSON is newer than database).
		if ( $modified && $modified > get_post_modified_time( 'U', true, $post['ID'] ) ) {
			$syncable[ $post['key'] ] = $post;
		}
	}

	return $syncable;
}