Support

Account

Home Forums ACF PRO Query two fields altogether

Solving

Query two fields altogether

  • This is my code, I want to show any of the field mother or father (if user fills any one).
    if user fills both the field, then , (comma should be appear between both field data).
    I am not a programmer, so please guide me.

    <div class="wDYxhc">
    	<div class="Z1hOCe">
    		<div class="zloOqf PZPZlf">
    			<div class="rVusze">
    				<?php if( get_field('parents') ): ?>
    					<span class="GRkHZd w8qArf"><a class="fl">Parents</a>: </span>
    					<span class="Eq0J8 LrzXr kno-fv" itemprop="parent"><?php the_field('parents'); ?></span>
    				<?php endif; ?>
    			</div>
    		</div>
    	</div>
    </div>

    above code is to fill both data in single field, but I want separate fileds like mother and father. and want to display in single row.

  • What kid of field is “parents”

  • Hi,
    Please see this for better understanding: https://infoobox.com/person/sunil-butolia

    Currently user can fill their parents details in single text box but I want to create separate for mother and father and want to show in single line as mentioned in above link.

    But what if someone only fills one details mother or father then how to remove ‘comma’.

  • That does not really explain the type of fields.

    What fields are you going to use? Will it be a repeater? Two text fields? What is the field hierarchy?

    What would the HTML and content look like using these 2 fields?

  • I’m simply using text fields (first option in the plugin)

    Actually I’m looking for…

    If this, this and this value is available then show them all (inline with comma separated)

    Otherwise show any available value (without any comma)
    I hope you understand this time.
    Thanks

  • The way I usually do this is to build an array from the field.

    
    $values = array();
    if (get_field('field_1') {
      $values[] = get_field('field_1');
    }
    if (get_field('field_2') {
      $values[] = get_field('field_2');
    }
    if (get_field('field_3') {
      $values[] = get_field('field_3');
    }
    

    Then I use implode do display

    
    if (!empty($values)) {
      echo implode(', ', $values);
    }
    
  • Thanks for your support,

    Now I have adopted relationship for my output and this question has resolved half of my problem.

    now I also want get_permalink( $person->ID ):

    <a href="<?php echo get_permalink( $person->ID ); ?>">
    	<?php echo get_the_title( $person->ID ); ?>
    </a>

    so that those values can linked to their respective post.

  • sorry this is not working, or i dont know where to put <?php code.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.