Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress Custom Post Type with ACF via shortcode
<?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
You can’t perform that action at this time.