Divi WordPress Theme
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix Reply To: How to call specific pages in one page

Discussion in 'Misc WordPress Requests' started by danielm1984, Dec 11, 2017.

  1. danielm1984


    Reply To: How to call specific pages in one page, by danielm1984

    This is for anyone that might be having the same problem.

    The code below will only work for children of the page you are viewing currently which for me was the home page.


    <?php $posts = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'DESC' ) );
    foreach( $posts as $post ) : ?>
    <h1><?php echo apply_filters( 'the_title', $post->post_title, $service->ID ); ?></h1>
    <?php echo get_the_post_thumbnail( $post->ID, 'thumbnail' ); ?>
    <?php echo apply_filters( 'the_content', $post->post_content ); ?>
    <a href="<?php echo get_page_link( $post->ID ); ?>"><?php echo View ?></a>
    <?php endforeach; ?>

    The code below is more specific to what I needed, which requires a database query.


    $querystr = "
    SELECT wposts.*
    FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    WHERE wposts.ID = wpostmeta.post_id
    AND wpostmeta.meta_key = 'what-we-do-descriptions'
    AND wposts.post_type = 'page'
    ORDER BY wpostmeta.meta_value DESC
    $pageposts = $wpdb->get_results($querystr, OBJECT);
    <?php $pageposts = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'DESC' ) ); ?>
    <?php foreach ($pageposts as $post): setup_postdata($post); ?>
    <h2><?php the_title(); ?></h2>
    if (has_post_thumbnail())
    <a href="<?php the_permalink() ?>" rel="bookmark" title="View more about <?php the_title_attribute(); ?>">View</a>
    <?php the_field('what-we-do-descriptions'); //can only display this after looking through all posts/pages with this "custom key type" ?>
    <?php endforeach; ?>

    Reply To: How to call specific pages in one page

Share This Page

Monarch Social Sharing Plugin