I am using the below to fetch the content of a page by its name and output the html
$my_wp_query = new WP_Query();
$page = $my_wp_query->query(
array(
'post_type' => 'page',
'name' => 'some-page-slug'
)
);
$page = $page[0];
$page_data['content'] = apply_filters('the_content', $page->post_content);
The field $page->post_content
unmodified contains a string with the content I have typed in the backend as well as a reference to the gallery in the form [gallery="1,2,3,4"]
at the end of the string. When I run it through the apply_filters('the_content', $page->post_content)
method, it restores the HTML tags such as the <p>
elements, however it also includes the gallery code which has its own style and quite lengthy markup as illustrated below.
<p>Residential Gallery. Etiam lobortis sapien vel erat sodales et suscipit leo pretium. Pellentesque a arcu sed velit congue sagittis ac vel erat. Curabitur non felis leo, vel vestibulum purus. Donec eget velit eget magna rutrum facilisis. In hac habitasse platea dictumst.</p>
<p>Quisque sit amet pellentesque risus. Aliquam erat volutpat. Ut at magna justo, tincidunt viverra odio. Pellentesque a arcu sed velit congue sagittis ac vel erat. Curabitur non felis leo, vel vestibulum purus. Donec eget velit eget magna rutrum facilisis. In hac habitasse platea dictumst. Quisque sit amet pellentesque risus. Aliquam erat volutpat.</p>
<p>Ut at magna justo, tincidunt viverra odio. Curabitur non felis leo, vel vestibulum purus. Donec eget velit eget magna rutrum facilisis. In hac habitasse platea dictumst. Quisque sit amet pellentesque risus. Aliquam erat volutpat. Ut at magna justo, tincidunt viverra odio.</p>
<style type='text/css'>
#gallery-1 {
margin: auto;
}
#gallery-1 .gallery-item {
float: left;
margin-top: 10px;
text-align: center;
width: 33%;
}
#gallery-1 img {
border: 2px solid #cfcfcf;
}
#gallery-1 .gallery-caption {
margin-left: 0;
}
</style>
<!-- see gallery_shortcode() in wp-includes/media.php -->
<div id='gallery-1' class='gallery galleryid-0 gallery-columns-3 gallery-size-thumbnail'><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://local.definitive-final2.co.uk/blog/residential/georgian-house/georgian1/' title='georgian1'><img width="150" height="150" src="http://local.definitive-final2.co.uk/blog/wp-content/uploads/2013/01/georgian1-150x150.jpg" class="attachment-thumbnail" alt="georgian1" /></a>
</dt></dl><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://local.definitive-final2.co.uk/blog/residential/georgian-house/georgian2/' title='georgian2'><img width="150" height="150" src="http://local.definitive-final2.co.uk/blog/wp-content/uploads/2013/01/georgian2-150x150.jpg" class="attachment-thumbnail" alt="georgian2" /></a>
</dt></dl><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://local.definitive-final2.co.uk/blog/residential/georgian-house/georgian3/' title='georgian3'><img width="150" height="150" src="http://local.definitive-final2.co.uk/blog/wp-content/uploads/2013/01/georgian3-150x150.jpg" class="attachment-thumbnail" alt="georgian3" /></a>
</dt></dl><br style="clear: both" /><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://local.definitive-final2.co.uk/blog/residential/georgian-house/georgian4/' title='georgian4'><img width="150" height="150" src="http://local.definitive-final2.co.uk/blog/wp-content/uploads/2013/01/georgian4-150x150.jpg" class="attachment-thumbnail" alt="georgian4" /></a>
</dt></dl><dl class='gallery-item'>
<dt class='gallery-icon'>
<a href='http://local.definitive-final2.co.uk/blog/residential/paris-house/paris4/' title='paris4'><img width="150" height="150" src="http://local.definitive-final2.co.uk/blog/wp-content/uploads/2013/01/paris4-150x150.jpg" class="attachment-thumbnail" alt="paris4" /></a>
</dt></dl>
<br style='clear: both;' />
</div>
I would like to only retrieve the HTML text with <p>
's etc and not the gallery's <style>
and <div>
tags.
How might I achieve this?