Forums

[resolved] Contact form 7 not shown with Get Page (8 posts)

  1. aminabbasian
    Member
    Posted 2 years ago #

    Hey Guys,

    I've put together a site which works as a Coda style slider. With each page called using the Get Page function such as:

    <?php
    $page_id = 7;
    $page_data = get_page( $page_id ); 
    
    $content = $page_data->post_content;
    $title = $page_data->post_title;
    echo $page_data->post_content;
    ?>

    However I do have one issue where contact form 7 is not showing. all that is shown is [contact-form 1 "contact"].

    There doesn't seem to be any plugin conflicts.

    Any ideas?!

    thanks

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    You're displaying raw page content ($page_data->post_content) instead of filtered/process content( the_content()).

  3. aminabbasian
    Member
    Posted 2 years ago #

    Thanks Esmi,

    I've tried the following:

    <?php if( !is_page('7') ) :?>
    <?php else the_content();
    <?php endif;?>

    but with no luck. This causes an error and blank page.
    Am I going on the right direction?

  4. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Try using get_posts instead?

    <?php
    $these_pages = get_posts('page_id=7');
    foreach($these_pages as $post) :
    setup_postdata($post);
    the_content();
    php endforeach;
    ?>
  5. aminabbasian
    Member
    Posted 2 years ago #

    same result.

    This is my full code:
    [Code moderated as per the Forum Rules. Please use the pastebin]

  6. aminabbasian
    Member
    Posted 2 years ago #

    The link to pastebin is http://wordpress.pastebin.com/bzdmqnZz

    Thanks

  7. mattyza
    Member
    Posted 2 years ago #

    Hi aminabbasian,

    Using your original code snippet, this may be a solution:

    <?php
    	$page_id = 7;
    	$page_data = get_page( $page_id ); 
    
    	$content = apply_filters( 'the_content', $page_data->post_content );
    	$title = $page_data->post_title;
    	echo $content;
    ?>

    Essentially, to render shortcodes, etc, the filters on the_content need to be applied.

    More on this is available at: http://codex.wordpress.org/Function_Reference/apply_filters

    I hope this helps. :)

    All the best,
    Matty.

  8. aminabbasian
    Member
    Posted 2 years ago #

    perfect! Worked a treat!

    many thanks

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.