Created
November 2, 2017 10:48
-
-
Save imlinus/5f22fb61ba85f73e8f056b3259ca06e8 to your computer and use it in GitHub Desktop.
WordPress Custom Post Type with ACF via shortcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function price_shortcode($id) { | |
if($id != '') { | |
$post_id = $id[0]; | |
$html = ''; | |
global $wpdb; | |
$args = array( | |
'post_type' => 'price_list_init', | |
'name' => $id | |
); | |
$wp_posts = new WP_Query($args); | |
$posts = $wp_posts->posts; | |
while ( $wp_posts->have_posts() ) : $wp_posts->the_post(); | |
$html = '<div class="' . create_slug(get_field('pl_title')) . ' price-table">'; | |
$html .= '<div class="header">'; | |
$html .= '<span class="price">' . get_field('pl_price') . '</span>'; | |
$html .= '<span class="name">' . get_field('pl_title') . '</span>'; | |
$html .= '</div>'; | |
$html .= get_field('pl_list'); | |
$html .= '<button>'; | |
$html .= '<a href="' . get_field('pl_button_url') . '">'; | |
$html .= get_field('pl_button_text'); | |
$html .= '</a>'; | |
$html .= '</button>'; | |
$html .= '</div>'; | |
endwhile; | |
wp_reset_query(); | |
return html_entity_decode($html); | |
wp_reset_postdata(); | |
} else { | |
return 'Please enter correct shortcode'; | |
} | |
} | |
add_shortcode('price', 'price_shortcode'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment