0
0
Wordpressframework~10 mins

Advanced Custom Fields plugin in Wordpress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get the value of a custom field named 'subtitle' in a WordPress template.

Wordpress
<?php $subtitle = get_field('[1]'); ?>
Drag options to blanks, or click blank then click option'
Asubtitle
Btitle
Ccontent
Dauthor
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong field name like 'title' or 'content' instead of 'subtitle'.
Forgetting to wrap the field name in quotes.
2fill in blank
medium

Complete the code to display a custom field called 'price' inside a paragraph tag.

Wordpress
<p>Price: <?php [1]('price'); ?></p>
Drag options to blanks, or click blank then click option'
Aget_field
Bthe_field
Cthe_content
Dget_post_meta
Attempts:
3 left
💡 Hint
Common Mistakes
Using get_field without echo, resulting in no output.
Using unrelated functions like the_content.
3fill in blank
hard

Fix the error in the code to correctly check if a custom field 'featured' is true before showing a badge.

Wordpress
<?php if([1]('featured')): ?>
  <span class="badge">Featured</span>
<?php endif; ?>
Drag options to blanks, or click blank then click option'
Aget_field
Bhave_rows
Cthe_field
Dget_post_meta
Attempts:
3 left
💡 Hint
Common Mistakes
Using the_field inside if condition causing syntax errors.
Using have_rows which is for repeater fields, not simple true/false.
4fill in blank
hard

Fill both blanks to create a loop that lists all items in a repeater field named 'features'.

Wordpress
<?php if(have_rows('[1]')): ?>
  <ul>
  <?php while(have_rows('[1]')): the_row(); ?>
    <li><?php the_sub_field('[2]'); ?></li>
  <?php endwhile; ?>
  </ul>
<?php endif; ?>
Drag options to blanks, or click blank then click option'
Afeatures
Bfeature_name
Cfeature
Ditems
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong field names that do not match the repeater or subfield.
Not repeating the repeater field name in both have_rows calls.
5fill in blank
hard

Fill all three blanks to create an associative array that maps each post ID to its custom field 'rating' if the rating is above 3.

Wordpress
<?php
$ratings = [];
foreach($posts as [3]):
  $rating = [2];
  if($rating > 3):
    $ratings[[1]] = $rating;
  endif;
enforeach;
?>
Drag options to blanks, or click blank then click option'
A$post->ID
Bget_field('rating', $post->ID)
C$post
D$post->post_title
Attempts:
3 left
💡 Hint
Common Mistakes
Using post title instead of ID as key.
Not passing post ID to get_field.
Using wrong variable names in the loop.