function register_tour_cta_block() { // Register the block editor script wp_register_script( 'tour-cta-block-js', plugins_url('/blocks/tour-cta-block.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-editor', 'wp-components') ); // Register the block register_block_type('your-plugin/tour-cta', array( 'editor_script' => 'tour-cta-block-js', 'render_callback' => 'render_tour_cta_block' )); } function render_tour_cta_block($attributes) { // Fetch the latest tour post $args = array( 'post_type' => 'tour', 'posts_per_page' => 1 ); $query = new WP_Query($args); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $post_id = get_the_ID(); // Assuming 'tour_primary_image' and 'tour_description' are custom fields $tour_image = get_post_meta($post_id, 'tour_primary_image', true); $tour_description = get_post_meta($post_id, 'tour_description', true); $tour_url = get_permalink($post_id); // Build HTML Output $output = '
' . esc_html($tour_description) . '
'; } $output .= 'Learn More'; $output .= ''; $output .= 'No tours available.
'; } } add_action('init', 'register_tour_cta_block');