“Отправить переменную в get_template_part” Ответ

Отправить переменную в get_template_part

//NEW CLEAN way (WP 5.5.0 >=) of passing variables to template parts 

$data = array('foo'=>'bar');

//add your variables as a third parameter
get_template_part( 'template-parts/file', 'name', $data );

//In the template part itself: (IMPORTANT NOTE: the name of the variable has to be args)
echo $args['foo'];
Andrew Lautenbach

Как пройти удостоверение личности через шаблон

<?php
get_header();

// etc.

// In the main template file
$users = new \WP_User_Query( [ ... ] );

foreach ( $users as $user )
{
    set_query_var( 'user_id', absint( $user->ID ) );
    get_template_part( 'template-parts/user', 'contact_methods' );
}
Dizzy Dog

Ответы похожие на “Отправить переменную в get_template_part”

Вопросы похожие на “Отправить переменную в get_template_part”

Больше похожих ответов на “Отправить переменную в get_template_part” по PHP

Смотреть популярные ответы по языку

Смотреть другие языки программирования