JRoy
9/9/2018 - 8:40 PM

Offers Code

{"offer":{"name":"offer","label":"Offers","singular_label":"Offer","description":"","public":"true","publicly_queryable":"true","show_ui":"true","show_in_nav_menus":"true","show_in_rest":"false","rest_base":"","has_archive":"false","has_archive_string":"","exclude_from_search":"false","capability_type":"post","hierarchical":"false","rewrite":"true","rewrite_slug":"","rewrite_withfront":"true","query_var":"true","query_var_slug":"","menu_position":"","show_in_menu":"true","show_in_menu_string":"","menu_icon":"dashicons-megaphone","supports":["title","editor","thumbnail"],"taxonomies":[],"labels":{"menu_name":"","all_items":"","add_new":"","add_new_item":"","edit_item":"","new_item":"","view_item":"","view_items":"","search_items":"","not_found":"","not_found_in_trash":"","parent_item_colon":"","featured_image":"","set_featured_image":"","remove_featured_image":"","use_featured_image":"","archives":"","insert_into_item":"","uploaded_to_this_item":"","filter_items_list":"","items_list_navigation":"","items_list":"","attributes":""},"custom_supports":""}}
function get_current_page_offer() {
    global $current_page_offer;
    $service_type = get_field('service_type');
    $offer_posts = get_posts(array(
    	'posts_per_page'	=> -1,
    	'post_type'			=> 'offer',
        'meta_key'		=> 'service_type',
    	'meta_value'	=> $service_type
    ));
    if( $offer_posts ){
    	 foreach( $offer_posts as $offer_post ){
    		setup_postdata( $offer_post );
            if( get_field('is_this_a_landing_page') !== 'Yes' ){
                $current_page_offer_array = array(
                    'offer_top_text' => get_field('offer_top_text', $offer_post->ID),
                    'offer_middle_text' => get_field('offer_middle_text', $offer_post->ID),
                    'offer_large_text' => get_field('offer_large_text', $offer_post->ID),
                    'offer_disclaimer' => get_field('offer_disclaimer', $offer_post->ID),
                );
                $current_page_offer = $current_page_offer_array;
            }
    	}
    	wp_reset_postdata();
    }else{
        $service_type = 'general';
        $offer_posts = get_posts(array(
        	'posts_per_page'	=> -1,
        	'post_type'			=> 'offer',
            'meta_key'		=> 'service_type',
        	'meta_value'	=> $service_type
        ));
        if( $offer_posts ){
        	 foreach( $offer_posts as $offer_post ){
        		setup_postdata( $offer_post );
                if( get_field('is_this_a_landing_page') !== 'Yes' ){
                    $current_page_offer_array = array(
                        'offer_top_text' => get_field('offer_top_text', $offer_post->ID),
                        'offer_middle_text' => get_field('offer_middle_text', $offer_post->ID),
                        'offer_large_text' => get_field('offer_large_text', $offer_post->ID),
                        'offer_disclaimer' => get_field('offer_disclaimer', $offer_post->ID),
                    );
                    $current_page_offer = $current_page_offer_array;
                }
        	}
        	wp_reset_postdata();
        }
    }
}
add_action( 'wp_head', 'get_current_page_offer' );