Custom API For Page with custom fields

PHOTO EMBED

Thu Jul 06 2023 12:04:39 GMT+0000 (Coordinated Universal Time)

Saved by @gshailesh27

//Custom API For Page with custom fields


// Custom rest API

add_action('rest_api_init', function () {
register_rest_route( 'bootscore-child-main/v1', 'home', array(
        'methods' => 'GET',
        'callback' => 'get_home_content',
    ) );
});

function get_home_content(){
	$id= 8;
	$siteUrl = site_url();
	$introTitle = get_cfc_field('home-banner-data', 'home-banner-title', $id );
	$introDesc = get_cfc_field('home-banner-data', 'home-banner-sub-text', $id );
	$introUrl = get_cfc_field('home-banner-data', 'home-banner-cta-url', $id );
	if($introTitle){
		$result['home-intro-title'] = $introTitle;
	}
	if($introDesc){
		$result['home-intro-desc'] = $introDesc;
	}
	if($introUrl){
		$result['home-into-url'] = $siteUrl.$introUrl;
	}
	return $result;
}

content_copyCOPY