R
R
romancho3542021-07-05 15:21:09
WordPress
romancho354, 2021-07-05 15:21:09

How to disable header for Custom post type in the_post()?

Each page displays Custom post type (banners) with ACF fields. It turns out that the_post() overrides wp_title().

functions.php

function get_banner($banner) {
    $result = [];
    $args = array(
        'post_type' => 'banners',
        'post_status' => 'publish',
        'public' => true,
        'hierarchical' => false,
        'post_per_page' => 10
    );
    $banners_loop = new WP_Query( $args );
    if ($banners_loop->have_posts()):
        while ( $banners_loop->have_posts() ) : $banners_loop->the_post();
            if( get_field('banner_type') == $banner) {
                $result= [
                    'imageDesktop' => get_field('banner_desktop'),
                    'imageMobile' => get_field('banner_mobile'),
                    'url' => get_field('banner_link'),
                    'urlMobile' => get_field('banner_link_mobile') ? get_field('banner_link_mobile') : get_field('banner_link')
                ];
            }
        endwhile;
        return $result;
    endif;
    wp_reset_postdata();
    wp_reset_query();
}
add_action('init', 'get_banner' );


single.php The question is how to remove the header request?
$banner300x600 = get_banner('sidebar');

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question