Support

Account

Forum Replies Created

  • Is $category formatted like: "{$term->taxonomy}_{$term->term_id}"? Getting field values from taxonomy fields is a little funky, full docs at: http://www.advancedcustomfields.com/resources/how-to-get-values-from-a-taxonomy-term/

  • Oh, you’ll probably want to put the query for the attached posts inside the loop and pass the ID. Maybe something like:

    
    <?php 
    $loop = new WP_Query( array( 'post_type' => 'clients', 'posts_per_page' => 10 ) );
    ?>
    <?php if($loop->have_posts()) : ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <div class="postbox-container postbox">
    <h3><?php the_title(); ?></h3>	
    
    <?php
    $ids = get_field('attach_to_client', $loop->ID);
    
    $query = new WP_Query(array(
    	'post_type'      	=> array('research', 'project_brief','persona','task_models', 'user_stories', 'style_guide'),
    	'posts_per_page'	=> -1,
    	'post__in'				=> $ids,
    	'post_status'			=> 'any',
      'orderby'       	=> 'modified',
    ));
    ?>
    
    <?php if ($query->have_posts()) : ?>
    <ul>
    <?php
    	while($query->have_posts()) :
    		$query->the_post();
    ?>
    	<li><?php the_title(); ?></li>
    
    <?php endwhile; ?>
    </ul>
    <?php else: ?>
    
          <p>Oops, there are no posts.</p>
    
    <?php endif; ?>
    </div>
    <?php endwhile; endif; wp_reset_query(); ?>
    
  • I don’t believe get_field() is ready in that particular hook. You’ll need to use get_post_meta() to retrieve the value instead:

    
    echo get_post_meta( $post_ID, 'project_navigation_name', true );
    
  • Check your wp_postmeta table for these entries. Though you removed the rule the meta data is likely still available, and being called by get_field().

  • That code is assuming your get_field('exhibitionstartdate') is in the format yyyymmdd. If you do:

    
    echo get_field('exhibitionstartdate');
    

    What is the output?

  • Is the checkbox just a true/false field? If so it would be:

    
    <?php 
    if ( get_sub_field('blog_style_gallery_options') ) {
      echo "border";
    }
    ?>
    
  • Would probably include something like this in your loop:

    
    <?php if( have_rows('repeater_field_name') ): ?>
      <?php 
      $slides = get_field('repeater_field_name'); 
      $total_slides = count($slides);
      $current_slide = 1;
      ?>
    
      <ul class="slides">
        <?php while( have_rows('repeater_field_name') ): the_row(); ?>
    
          <li class="slide">
            <?php $image = get_sub_field('image'); ?>
            <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
            <span class="count"><?php echo $current_slide++; ?> of <?php echo $total_slides; ?></span>
          </li>
    
        <?php endwhile; ?>
    
      </ul>
    <?php endif; ?>
    
  • In your template file for the single product (possibly single-product.php) you can use get_field() to get your field data.

    
    <?php echo get_field( 'discount' ); ?>
    

    If on another page you’ll also need to pass in the post ID. So if you’re on the homepage you’ll need to pass the product ID that you’d like to get the value for:

    
    <?php echo get_field( 'discount', $product_id ); ?>
    
  • Couple things:

    1. On get_field in this manner you may need to pass two additional parameters according to the docs at http://www.advancedcustomfields.com/resources/relationship/
    2. Sometimes post_type => 'any' fails, so might be worth a shot with a set array just to test
    
    <?php 
    $ids = get_field('attach_to_client', false, false);
    
    $query = new WP_Query(array(
    	'post_type'      	=> array('post','page'),
    	'posts_per_page'	=> 10,
    	'post__in'		=> $ids,
    	'post_status'		=> 'any',
            'orderby'        	=> 'modified',
    ));
    ?>
    <h3><?php get_field( 'clients' ) ?></h3>	
    <?php if ($query->have_posts()) : ?>
    <ul>
    <?php
    	while($query->have_posts()) :
    		$query->the_post();
    ?>
    	<li><?php the_title(); ?></li>
    
    <?php endwhile; ?>
    </ul>
    <?php else: ?>
    
          <p>Oops, there are no posts.</p>
    
    <?php
       endif;
    ?>
    
  • Interesting, your new template shouldn’t need to be registered – if it’s loading it should be set.

    Have you tried your code within the init hook like @elliot mentioned in that post?

    
    add_action('init', function() {
    ?>
    <?php if(get_field('video_slider', 'option')): ?>					
      <?php while(has_sub_field('video_slider', 'option')): ?>
        <?php $image = get_sub_field('image');?>
        <li class="home-lead-image">
          <a href="<?php the_sub_field('link'); ?>">
    	<img class="img-responsive upsize" style="visibility: hidden;" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>"/>
    	<img class="img-responsive parallax upsize" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>"/>
    	<div class="container-fluid">
    	  <div class="col-sm-6">
    	    <h1><?php the_sub_field('text'); ?></h1>
    	  </div>
    	</div>
          </a>
        </li>
      <?php endwhile; ?>					
    <?php endif; ?>		
    <?php
    });
    
  • Ah, maybe like:

    
    <?php if (in_array("Administration", (array) get_field('dir-department')) || ('yes' == get_field('dir-department-head'))): ?>
    
  • Could do something like:

    
    /*
    *  Create a new post and add field data
    *  - if the post does not already contain a "reference" to the field object, you must use the field_key instead of the field_name.
    */
    
    // Create post object
    $my_post = array(
     'post_title' => 'My post',
     'post_content' => 'This is my post.',
     'post_status' => 'publish',
     'post_author' => 1
    );
    
    // Insert the post into the database
    $post_id = wp_insert_post( $my_post );
    
    // Add field value
    update_field( "field_5039a99716d1d", "I am a value!", $post_id );
    

    Snippet from: http://www.advancedcustomfields.com/resources/update_field/

  • Interesting it’s working on the homepage, the syntax seems like it would need to be tweaked to:

    
    <!-- Start homepage slider -->
    <div class="home-banner flexslider-home">
    		<ul class="slides">
    		
    				<?php if (have_rows('video_slider', 'option')): ?>					
    					<?php while(have_rows('video_slider', 'option')): the_row(); ?>
    					<?php $image = get_sub_field('image');?>
    					
    						<li class="home-lead-image">
    							<a href="<?php the_sub_field('link'); ?>">
    							<img class="img-responsive upsize" style="visibility: hidden;" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>"/>
    														
    							<img class="img-responsive parallax upsize" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>"/>
    							
    							<div class="container-fluid">
    								<div class="col-sm-6">
    									<h1><?php the_sub_field('text'); ?></h1>
    								</div>
    							</div>
    							</a>
    							
    						</li>
    				
    					<?php endwhile; ?>					
    				<?php endif; ?>		
    				
    		</ul>
    </div>
    <div class="container-fluid">
    	<div class="banner-direction-nav">
    		<a class="prev">◀</a>
    		<a class="next">▶</a>
    	</div>
    </div>
    <!-- End homepage slider -->
    
  • You should just be able to say get_field( 'location' ) when listing out your programs and it should return an array of IDs or Post Objects (depending on the return value you selected for the Relationship field).

  • One possible route is to query for the Department Head first, and then do a second query to get the remaining posts excluding the Department Head post id. It would be using the exclude parameter from get_postshttp://codex.wordpress.org/Template_Tags/get_posts

  • Your code looks correct, however, query_posts is used to modify the main query of the post/page you’re on. You’ll probably want to use get_posts instead. The rest remains the same:

    
    $args = array(
      'post_type'     => 'post',
      'cat'      => 399,
      'posts_per_page'    => -1,
      'meta_query'        => array(
        array(
          'key' => 'organization_type',
          'value' => 'socialbusiness',
        )
      )
    );
    ?>
    
    <?php
    $social_businesses = get_posts( $args );
    
    if ( $social_businesses ): ?>
      <?php foreach ( $social_businesses as $sb ): ?>
        <a href="<?php echo get_permalink( $sb->ID ); ?>"><?php echo get_the_title( $sb->ID ); ?></a><br>    
      <?php endforeach; ?>
    <?php endif; ?>
    
  • Weird, if you echo $prev_post->ID is it filled in?

  • Assuming the $cats is receiving values it seems like you’ll want to update the code to:

    
    <?php
    $cats = get_field('rel_posts_cat');
    $my_query = new WP_Query(array(
    	'showposts' => '10',
    	'category__and' => $cats, 
    ));
    while ( $my_query->have_posts() ) : $my_query->the_post();
    ?>
    

    The change is on the 'category__and' parameter, since $cats should be returning an array assuming you’ve defined the Return Value to Term ID

  • Might try:

    
    <p><?php echo get_field( 'show_this_tomrorow', $prev_post->ID ); ?></p>
    
  • Ah, that makes sense. So this is rather a reverse relationship query. In that case your friend was correct, but it can be done in a single query:

    
    <?php
    $related_posts = get_posts(array(
      'post_type' 	  => 'post',
      'numposts'	  => -1,
      'post_status'	  => 'publish',
      'orderby'	  => 'title',
      'order'         => 'ASC',
      'meta_query' 	  => array(
        array(
          'key'     => 'related_products',
          'value'	=> '"' . get_the_ID() . '"',
          'compare' => 'LIKE'
        ),
      )
    ));
    ?>
    
    <?php if ( $related_posts ): ?>
      <ul class="medium-block-grid-5 blog-posts">
        <?php foreach( $related_posts as $rp ): ?>
          <li class="post">
            <a href="<?php echo get_permalink( $rp->ID ); ?>" title="<?php the_title_attribute( array( 'post' => $rp->ID ) ); ?>" ><span class="featured-title"><h3><?php echo get_the_title( $rp->ID ); ?></h3></span></a>
            
            <?php if ( has_post_thumbnail( $rp->ID ) ) : ?>
    	  <?php echo get_the_post_thumbnail( $rp->ID, 'regular-posts' ); ?>
    	<?php else : ?>
    	  <img src="<?php echo get_template_directory_uri(); ?>/img/no-image.png" alt="" />
    	<?php endif; ?>
          </li>
        <?php endforeach; ?>
      </ul>
    <?php endif; ?>
    
  • Certainly. That proposed solution does sound quite a bit more complex than necessary (essentially duplicating what ACF should be doing currently).

    If you do:

    
    $products = get_field('related_products');
    print_r($products);
    

    On a post you know to contain related products what do you get back?

  • So this is assuming you’re using the Relationship field type with the return format set to Post Object:

    
    <ul class="medium-block-grid-5 blog-posts">	
    <?php if ( $products = get_field('related_products') ): ?>
      <?php foreach( $products as $p ): ?>
        <li class="post">
          <a href="<?php the_permalink( $p->ID ); ?>" title="<?php the_title_attribute( array( 'post' => $p->ID ) ); ?>" ><span class="featured-title"><h3><?php echo get_the_title( $p->ID ); ?></h3></span></a>
          
          <?php if ( has_post_thumbnail( $p->ID ) ) : ?>
            <?php echo get_post_thumbnail( $p->ID, 'regular-posts' ); ?>
          <?php else : ?>
            <img src="<?php echo get_template_directory_uri(); ?>/img/no-image.png" alt="" />
          <?php endif; ?>
        </li>
      <?php endforeach; ?>
    <?php endif; ?>
    </ul>
    

    Summary is that you don’t need to put this inside a WordPress loop, you can just iterate over the related posts and call the desired functions on that specific post (in this cast product) ID.

  • This can be done just through the stylesheet. So say for example you have the following in your archive file:

    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
      <div class="entry-content">
         Content outputting here... 
      </div>
    <?php endwhile; ?>
    <?php endif; ?>
    

    I believe each element should be wrapped in something already, like a <div> or <article> or similar. You’ll just target that with your CSS and make it two-columns. So for the example snippet above you’d probably have some CSS like:

    
    .archive-employees .entry-content {
      float: left;
      width: 50%;
    }
    

    That .archive-employees bit is whatever class is currently on the <body> element on your archive page. Might need some tweaking but that’s the general idea.

  • Ah, so get_field does not output the value, to do that you’ll need to either echo it or use the_field instead:

    
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php echo get_field('employee_title'); ?>
    

    or

    
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php the_field('employee_title'); ?>
    

    For doing conditional fields you’ll just need to wrap it in a conditional like:

    
    <?php if ( $linkedin = get_field( 'linkedin' ) ): ?>
    <a href="<?php echo $linkedin; ?>">View LinkedIn</a>
    <?php endif; ?>
    
Viewing 25 posts - 26 through 50 (of 57 total)