if ( has_post_thumbnail() ) {
$background_image = get_the_post_thumbnail_url();
} else {
$background_image = get_stylesheet_directory_uri() . '/assets/img/default.jpg';
}
echo '<section class="section first-screen" style="background: url(' . $background_image . ') center/cover no-repeat">';
$tag = new WPCF7_FormTag( $tag );
if ( empty( $tag->name ) ) {
return '';
}
$args = [
'post_type' => 'programs',
'post_status' => 'publish',
'posts_per_page' => -1,
];
$html = '';
$options = array();
// пишем текущую запись в массив $options и исключаем из выборки get_posts()
if ( is_single() && get_post_type() === 'programs' ) {
$args['post__not_in'][] = get_the_ID(),
$options[] = get_the_title();
}
// берем посты из базы
if ( $posts = get_posts( $args ) ) {
foreach ( $posts as $key => $post ) {
$options[] = $post->post_title;
}
}
// собираем <select>
if ( !empty( $options ) ) {
$html .= '<select name="' . $tag->name . '" id="' . $tag->name . '-options">';
foreach ( $options as $key => $option ) {
$html .= '<option value="' . esc_html( $option ) . '">' . esc_html( $option ) . '</option>';
}
$html .= '</select>';
}
return $html;
GET https://www.googleapis.com/youtube/v3/videos?id=sTPtBvcYkO8&key=YOUR_API_KEY&part=statistics
{
"kind": "youtube#videoListResponse",
"etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/XN5YXMZGQaruwTWTekZu7fQthdY\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/QbzZs_aBNpzkZJxTVM7YgQeEY3g\"",
"id": "sTPtBvcYkO8",
"statistics": {
"viewCount": "3215321",
"likeCount": "17003",
"dislikeCount": "263",
"favoriteCount": "0",
"commentCount": "621"
}
}
]
}
$array = array();
$i = 1;
// собираем занчения в массив
while ( $i <= 15 ) {
if ( $field = get_field( 'item' . $i ) ) {
$array[] = $field;
}
$i++;
}
// выводим, если массив не пустой
if ( !empty( $array ) ) {
echo '<ul>';
foreach ( $array as $key => $value ) {
echo '<li>' . $value . '</li>';
}
echo '</ul>';
}
add_filter( 'query_vars', 'add_query_vars' );
function add_query_vars( $qvars ) {
$qvars[] = 'month';
$qvars[] = 'year';
return $qvars;
}
get_query_var()
if ( $month = get_query_var( 'month', false ) ) {
# code...
}
add_query_arg()
$link = add_query_arg( [ 'month' => '11', 'year' => '2021', ], get_home_link() );