首頁>Web>source

我用 template_lock   鎖定一些古腾堡塊.但我想在三種不同的帖子型別中使用它。

get_post_type_object();   只接受字元串,不接受陣列。

如何在不重複三遍相同功能的情况下使用几種帖子型別?

function wp_template_lock_subject_imposed() {
    $post_type_object = get_post_type_object( 'subject-imposed' );
    $post_type_object->template = array(
        array( 'acf/text-introduction'),
        array( 'acf/text-paragraph')
    );
    $post_type_object->template_lock = false;
}
add_action( 'init', 'wp_template_lock_subject_imposed' );
function wp_template_lock_subject_free() {
    $post_type_object = get_post_type_object( 'subject-free' );
    $post_type_object->template = array(
        array( 'acf/text-introduction'),
        array( 'acf/text-paragraph')
    );
    $post_type_object->template_lock = false;
}
add_action( 'init', 'wp_template_lock_subject_free' );
function wp_template_lock_dissertation() {
    $post_type_object = get_post_type_object( 'dissertation' );
    $post_type_object->template = array(
        array( 'acf/text-introduction'),
        array( 'acf/text-paragraph')
    );
    $post_type_object->template_lock = false;
}
add_action( 'init', 'wp_template_lock_dissertation' );
最新回復
  • 2020-5-27
    1 #

    這比wordPress問题更像是一个PHP問题,但是您可以執行以下操作:

    function wp_template_lock_example() {
        // Make an array of your post types
        $post_types = array('subject-imposed', 'subject-free', 'dissertation');
        // Loop the array and apply the template details to each.
        foreach ( $post_types as $post_type ) {
            $post_type_object = get_post_type_object( $post_type );
            $post_type_object->template = array(
                array( 'acf/text-introduction'),
                array( 'acf/text-paragraph')
            );
           $post_type_object->template_lock = false;
        }
    }
    add_action( 'init', 'wp_template_lock_example' );
    

    希望有帮助!

  • wordpress:無法在TInyMCE Iframe(jQuery)中收听KeyDown並將其傳遞给父HTML FORM
  • wordpress:Ajax响應未收到