I like to output and style in a shortcode, but the content that is get is the content of a page, so it’s style like that
<p>2012-12-12</p>
<p>2012-6-23</p>
<p>2012-7-3</p>
i like to be able to have ONLY the value date in a array to be able to output it in a unorder list after
how do i do that (strip the p and get it into an array ?
some code :
//Add a SHORTCODE to get date listing
add_shortcode ('getdate','get_date_listing');
function get_date_listing ($att) {
$req_id = 901;
$post = get_page($req_id);
$content = apply_filters('the_content', $post->post_content);
$contentarray = explode( 'n', $content );
echo ($contentarray[0]);
//var_dump ($contentarray);
//return $content;
}
Firstly, you need to remove the paragraph tags that were added by the
wp_autop
filter. There’s another answer that covers this pretty well: Is there an uw-wp_autop function?I’m going to change the function a little for our purposes (based on the markup example you gave):
If all is working correctly, this should convert your markup from:
To:
If you do a split now, you’ll end up with an extra, empty element in your array. So remember to take a substring before you split:
here is the final working code :