0

I created wp-theme, use plugin Custom Post Type UI.

Created sections - Customers and Projects.

enter image description here

enter image description here

enter image description here

In page-projects.php, display list (links) all of customers:

enter image description here

$args = array(
     'post_type' => 'customer'
   );
$the_query = new WP_Query( $args );

Im trying to display content from post projects (about customer). Page single-customer.php display content from customers, but I need post from projects.

enter image description here

How get this post content? Its possible?

UPD

code in single-customer.php:

  `<div class="page-head text-center">
    <div class="container">
        <h1 class="page-head_title"><?php the_title(); ?></h1>
        <p><?php the_subtitle(); ?></p>
    </div>
</div>




<?php
// This is for projects posts
$args = array(
    'post_type' => 'project'
);
$the_query = new WP_Query( $args );
?>
<?php if ($the_query->have_posts()) : ?>
    <?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
        // loop here
        <?php the_title(); ?>
        <?php the_content(); ?>
    <?php endwhile;
    wp_reset_postdata();
else : ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>`

UPD

if i use this code <?php acf_form(); ?> its display content which i need, but its display all textarea and inputs of wp-admin panel. if i use <?php the_field('project-sections'); ?> - its display Array, Array, Array, Array

2
  • @Marina , you want to add "projects" posts in single-customer.php ? it seems two custom post loop in the same page.
    – Ronald
    Jun 16, 2017 at 4:48
  • yes, i want to display post 'projects' in page 'single-customer.php'. how to do it?
    – siberian
    Jun 16, 2017 at 5:22

2 Answers 2

1

Multiple loops in the same page

<?php
// this is for customer posts
$args = array(
 'post_type' => 'customer'
   );
$the_query = new WP_Query( $args );
            ?>
            <?php if ($the_query->have_posts()) : ?>
                <?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
 <?php     // loop here
  the_title(); 
the_content(); ?>
<?php endwhile; 
 wp_reset_postdata();
 else : ?>
 <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
 <?php endif; ?>

<?php
    // This is for projects posts
$args = array(
 'post_type' => 'projects'
   );
$the_query = new WP_Query( $args );
            ?>
            <?php if ($the_query->have_posts()) : ?>
                <?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<?php     // loop here
  the_title(); 
the_content(); ?>
<?php endwhile; 
 wp_reset_postdata();
 else : ?>
 <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
 <?php endif; ?>

You can also mix the posts like this

'post_type' => array('customer', 'projects'),
11
  • this code need to add in single-customer.php and single-project.php ?
    – siberian
    Jun 16, 2017 at 7:05
  • You can add the codes in any page you like. To get the projects posts appear in single-customer.php, you don't have to create another single-project.php. ( Creating single-{custom}.php is only for single template. )
    – Ronald
    Jun 16, 2017 at 7:44
  • i add this code in page-customer.php - its display list of all customers, but dont get content post in project section. thank you for try to help, but i dont understand how use it
    – siberian
    Jun 16, 2017 at 9:12
  • Make sure the custom post name is correct , "project" or "projects". To get the right answer, you will have to be more specific in your question. I suggest you to copy all your codes and ask here again.
    – Ronald
    Jun 16, 2017 at 9:46
  • i try "project" and "projects", not help. i update my question
    – siberian
    Jun 16, 2017 at 10:32
0

i found solution:

<?php if( have_rows('project-sections') ): ?>
        <?php $i = 0; ?>

        <?php while( have_rows('project-sections') ): the_row(); ?>

            <section class="<?php if ($i % 2 == 0) : ?>bg-gray<?php else: ?>bg-white<?php endif; ?>">
                <div class="container">
                    <h2 class="page-head_sub-title"><?php the_sub_field('project-sections-title'); ?></h2>
                    <?php the_sub_field('project-sections-description'); ?>
                </div>
            </section>

            <?php $i++; ?>

        <?php endwhile; ?>

    <?php endif; ?>

Need to use

<?php the_sub_field('name-sub-field'); ?>

inside

<?php while( have_rows('name-field') ): the_row(); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.