I've some buttons on a page and I wanna make a div with the content of a WordPress post to be show only when the related button is clicked.
Once I have so many buttons and posts, I was wondering if that is a way to get the value with the name of the button ID that will be clicked with jQuery and since the post name related is the same, insert it on php to get the content.
I'm not sure if I could do something like this:
<div id="btn-group">
<button id="History">History</button>
<button id="Mathematic">Mathematic</button>
<button id="Geography">Geography</button>
<button id="Biology">Biology</button>
</div>
<div id="pages-content">
<?php $page = get_page_by_title( '*something to put the var currentID*' ); echo apply_filters('the_content', $p->post_content);?>
</div>
And the jQuery
jQuery(document.body).click(function(evt){
var clicked = evt.target;
var currentID = clicked.id;
})
// show the div only when the button is clicked
jQuery(document).on('click', function(e) {
if ( jQuery(e.target).closest('#btn-group').length ) {
jQuery('#pages-content').show();
}
});