Using nested shortcodes across different post types
-
Hello, I am trying a new way to layout my content but I have hit a snag.
The site I’m working on is sort of an homage to an old local newspaper, with several “articles”.
Because of this I have added a post type “articles”, which will be referenced by an article shortcode with the specific article id.
[article id=#]
will go into another custom post type “columns”, which would be entered into a PAGE type post like so:
[column id=#]So it seems to me that this would be shortcode nesting, even though they aren’t on the same “page” in the backend.
Here are my shortcode functions:
function art_display_shortcode_fn ( $atts ) { // allows an admin to enter articles into columns via shortcode like so: [article id=#] where id is the post id number extract(shortcode_atts(array('id' => ''), $atts)); $article_post_id = $id; $post_object = get_post( $article_post_id ); echo '<div class="articlecontainer">'; echo '<h2 class="list_title">'.$post_object->post_title,'</h2></a>'; echo '<p class="list_excerpt">'.$post_object->post_content,'</p>'; } add_shortcode( 'article', 'art_display_shortcode_fn' ); function column_display_shortcode_fn ( $atts, $content = null ) { // allows an admin to enter columns into posts and pages via shortcode like so: [column id=#] where id is the post id number extract(shortcode_atts(array('id' => '', 'article_post_id' => ''), $atts)); $post_id = $id; $post_object = get_post( $post_id ); return '<div class="column">' . do_shortcode($content) . '</div>'; } add_shortcode( 'column', 'column_display_shortcode_fn' );When I try it with this I get the
<div class="column">to show up on the front-end, but it is not containing the articles as I believe it should.
The topic ‘Using nested shortcodes across different post types’ is closed to new replies.