ACF CPT two columns with each category

I have created custom post types and added some things through advanced custom fields.
Usually when i don’t need to select from each category i would do something like this.

<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
<?php the_field('name_of_field'); ?>
endwhile; else: ?>

<?php endif; ?>

However now i have to select if it is one of two particular categories and then put category ‘tjanster’ in left column and ‘produkter’ in right column within my bootstrap grid.
So it will be 50% ‘tjanster’, 50% ‘produkter’.
I have been searching like crazy for an solution but only found some code for functions.php that didn’t work and 5years old posts that didn’t work for me.

Read More

What am i suposed to to so i can have some similar output like this?

<div class="container">
  <div class="row">

    <div class="col-sm-6">
       <!-- Output of category tjanster. -->
    </div>

    <div class="col-sm-6">
       <!-- Output of category produkter. -->
    </div>

  </div>
</div>

Related posts

Leave a Reply

1 comment

  1. For each column you need a WP_Query(). See codex for reference: http://codex.wordpress.org/Class_Reference/WP_Query.

    <div class="container">
      <div class="row">
        <div class="col-sm-6">
    
          <?php // tjanster
          $args1 = array(
            'category_name' => 'tjanster'
            );
    
          $query1 = new WP_Query( $args1 );    
          while ( $query1->have_posts() ) : $query1->the_post(); ?>
          <h2><?php the_title(); ?></h2>
          <?php the_content(); ?>
        <?php endwhile; 
        wp_reset_postdata(); ?>
    
      </div>
    
      <div class="col-sm-6">
    
          <?php  // produkter
          $args2 = array(
            'category_name' => 'produkter'
            );
    
          $query2 = new WP_Query( $args2 );    
          while ( $query2->have_posts() ) : $query2->the_post(); ?>
          <h2><?php the_title(); ?></h2>
          <?php the_content(); ?>
        <?php endwhile; 
        wp_reset_postdata(); ?>
    
      </div>
    </div>
    </div>