Created
August 25, 2020 13:49
-
-
Save n7studios/eecdd0b298a4d82ecbf8379a622000f5 to your computer and use it in GitHub Desktop.
Page Generator Pro: Define Advanced Custom Field Post Object Field Value on Generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Page Generator Pro: Define Advanced Custom Field Post Object Field Value on Generation | |
* Plugin URI: http://www.wpzinc.com/ | |
* Version: 0.0.1 | |
* Author: WP Zinc | |
* Author URI: http://www.wpzinc.com | |
* Description: Defines Advanced Custom Field Post Object Field Value on Generation | |
*/ | |
/** | |
* Defines Advanced Custom Field Values on Generated Pages | |
* | |
* @since 0.0.1 | |
* | |
* @param int $post_id Generated Post ID | |
* @param int $group_id Group ID | |
* @param array $settings Group Settings | |
* @param int $index Keyword Index | |
* @param bool $test_mode Test Mode | |
*/ | |
function page_generator_pro_define_acf_post_object_field_value( $post_id, $group_id, $settings, $index, $test_mode ) { | |
// Some basic sanity checks that ACF and Page Generator Pro functions exist | |
if ( ! function_exists( 'update_field' ) ) { | |
return; | |
} | |
if ( ! function_exists( 'Page_Generator_Pro' ) ) { | |
return; | |
} | |
// If deriving a Post ID value from Keywords, access the array of keyword / term key/value pairs for this specific generated Page | |
/* | |
$keywords_terms = Page_Generator_Pro()->get_class( 'generate' )->keywords_terms; | |
$value = $keywords_terms['post_id']; // e.g. if a Keyword called {post_id} exists | |
*/ | |
// If deriving a Post ID based on your own logic, apply it here | |
$value = 26881; | |
// Update ACF Post Object Field's Value | |
update_field( 'post', $value, $post_id ); | |
} | |
add_action( 'page_generator_pro_generate_content_finished', 'page_generator_pro_define_acf_post_object_field_value', 10, 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment