Bird
Raised Fist0
Wordpressframework~20 mins

Advanced Custom Fields plugin in Wordpress - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
ACF Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What is the output of this ACF field retrieval code?
Given a custom field named subtitle added via Advanced Custom Fields to a post, what will this code output inside the Loop?

echo get_field('subtitle');
Wordpress
<?php
// Inside the WordPress Loop
echo get_field('subtitle');
?>
AIt outputs the string 'subtitle' literally.
BIt outputs the value of the 'subtitle' custom field for the current post.
CIt outputs the field key instead of the value.
DIt causes a fatal error because get_field() requires a post ID argument.
Attempts:
2 left
💡 Hint
Remember that get_field() inside the Loop automatically uses the current post ID.
📝 Syntax
intermediate
2:00remaining
Which option correctly registers a new ACF field group with PHP?
You want to register a new ACF field group programmatically using PHP. Which code snippet is correct?
Aregister_acf_field_group(array('key' => 'group_1', 'title' => 'Test Group'));
Bacf_register_field_group(array('key' => 'group_1', 'title' => 'Test Group', 'fields' => array(), 'location' => array()));
Cacf_add_local_field_group(array('key' => 'group_1', 'title' => 'Test Group', 'fields' => array(), 'location' => array(array(array('param' => 'post_type', 'operator' => '==', 'value' => 'post')))));
Dadd_acf_field_group('group_1', 'Test Group', array());
Attempts:
2 left
💡 Hint
Look for the official ACF function to add local field groups.
❓ state_output
advanced
2:00remaining
What is the value of $image_url after this ACF image field retrieval?
Assuming an ACF image field named header_image returns an array, what will be the value of $image_url after this code?

$image = get_field('header_image');
$image_url = $image['url'];
Wordpress
<?php
$image = get_field('header_image');
$image_url = $image['url'];
?>
AAn array containing image metadata.
BA PHP error because 'url' key does not exist.
CNULL because get_field returns a string by default.
DThe URL string of the image stored in the 'header_image' field.
Attempts:
2 left
💡 Hint
When an image field returns an array, it includes keys like 'url', 'alt', and 'sizes'.
🔧 Debug
advanced
2:00remaining
Why does this ACF repeater field loop not output any rows?
This code is intended to loop through a repeater field named features but outputs nothing. Why?

if( have_rows('features') ) {
while( have_rows('features') ) {
the_row();
echo get_sub_field('feature_name');
}
}
Wordpress
<?php
if( have_rows('features') ) {
  while( have_rows('features') ) {
    the_row();
    echo get_sub_field('feature_name');
  }
}
?>
AThe repeater field 'features' is empty or not assigned to the current post.
Bthe_row() must be called before have_rows() in the loop.
Cget_sub_field() cannot be used inside have_rows() loops.
DMissing a call to reset_rows() before the loop.
Attempts:
2 left
💡 Hint
Check if the repeater field has data for the current post.
🧠 Conceptual
expert
2:00remaining
Which option best describes how ACF stores custom field data in the WordPress database?
Advanced Custom Fields stores custom field data in the WordPress database. How does it store this data?
AACF stores each custom field value as a separate postmeta entry with the field name as meta_key.
BACF stores all custom field data as serialized arrays in a single meta_key per post.
CACF stores custom fields in a separate custom database table outside of postmeta.
DACF stores custom fields as JSON strings inside the post_content field.
Attempts:
2 left
💡 Hint
Think about how WordPress normally stores custom fields.

Practice

(1/5)
1. What is the main purpose of the Advanced Custom Fields (ACF) plugin in WordPress?
easy
A. To add and manage extra custom fields without changing the database manually
B. To create new WordPress themes automatically
C. To speed up WordPress site loading times
D. To backup WordPress site data

Solution

  1. Step 1: Understand what ACF does

    ACF allows users to add custom fields easily without coding database changes.
  2. Step 2: Compare options

    Only To add and manage extra custom fields without changing the database manually describes adding and managing extra fields without manual database edits.
  3. Final Answer:

    To add and manage extra custom fields without changing the database manually -> Option A
  4. Quick Check:

    ACF purpose = add/manage custom fields [OK]
Hint: ACF is for custom fields, not themes or backups [OK]
Common Mistakes:
  • Confusing ACF with theme builders
  • Thinking ACF speeds up site loading
  • Assuming ACF handles backups
2. Which of the following is the correct way to retrieve a custom field value named subtitle using ACF in a WordPress template?
easy
A. the_field('subtitle');
B. fetch_field('subtitle');
C. get_field('subtitle');
D. custom_field('subtitle');

Solution

  1. Step 1: Identify the correct ACF function for retrieving values

    The function get_field() returns the value of a custom field.
  2. Step 2: Check other options

    the_field() echoes the value, not returns it; others are invalid functions.
  3. Final Answer:

    get_field('subtitle'); -> Option C
  4. Quick Check:

    Retrieve field value = get_field() [OK]
Hint: Use get_field() to get value, the_field() to print directly [OK]
Common Mistakes:
  • Using the_field() when value is needed for logic
  • Using non-existent functions like fetch_field()
  • Confusing echo and return functions
3. Consider this code snippet in a WordPress template using ACF:
$subtitle = get_field('subtitle');
if ($subtitle) {
  echo "

$subtitle

"; } else { echo "

No subtitle found

"; }

What will be the output if the custom field subtitle is empty or not set?
medium
A. PHP error will occur
B.

C. Nothing will be displayed
D.

No subtitle found

Solution

  1. Step 1: Understand the if condition

    The code checks if $subtitle has a value. If empty or not set, condition is false.
  2. Step 2: Check the else block output

    If false, it echoes "

    No subtitle found

    ".
  3. Final Answer:

    <h2>No subtitle found</h2> -> Option D
  4. Quick Check:

    Empty field triggers else output [OK]
Hint: Empty fields trigger else block output [OK]
Common Mistakes:
  • Assuming empty string prints empty <h2>
  • Expecting no output when field is empty
  • Thinking PHP error occurs on missing field
4. You have this code in your WordPress template:
echo get_field('price');

Sometimes it shows nothing and breaks the page layout. What is the best way to fix this issue?
medium
A. Remove the get_field() call completely
B. Check if the field has a value before echoing it
C. Use the_field() instead of get_field()
D. Change the field name to 'price_value'

Solution

  1. Step 1: Identify the problem cause

    Echoing an empty or null field can break layout if no fallback is provided.
  2. Step 2: Apply a check before echoing

    Use if (get_field('price')) to ensure value exists before output.
  3. Final Answer:

    Check if the field has a value before echoing it -> Option B
  4. Quick Check:

    Always check field value before output [OK]
Hint: Always verify field value exists before printing [OK]
Common Mistakes:
  • Removing field call instead of fixing output
  • Using the_field() which echoes without checks
  • Changing field name without updating code
5. You want to display a list of team members with their custom fields: name, role, and photo. Which approach correctly uses ACF to loop through a repeater field called team_members and display each member's info?
hard
A.
if (have_rows('team_members')) {
  while (have_rows('team_members')) {
    the_row();
    echo get_sub_field('name');
    echo get_sub_field('role');
    echo '';
  }
}
B.
foreach (get_field('team_members') as $member) {
  echo $member['name'];
  echo $member['role'];
  echo '';
}
C.
while (have_rows('team_members')) {
  echo get_sub_field('name');
  echo get_sub_field('role');
  echo get_sub_field('photo');
}
D.
if (get_field('team_members')) {
  echo get_field('team_members')['name'];
  echo get_field('team_members')['role'];
  echo get_field('team_members')['photo'];
}

Solution

  1. Step 1: Understand repeater field usage

    Repeater fields require have_rows() and the_row() to loop through rows.
  2. Step 2: Check sub field retrieval

    Use get_sub_field() inside the loop to get each subfield value.
  3. Step 3: Verify image field handling

    Image fields return an array; access ['url'] for the image source.
  4. Final Answer:

    Correct repeater loop with have_rows(), the_row(), get_sub_field(), and image url access -> Option A
  5. Quick Check:

    Repeater loop = have_rows() + the_row() + get_sub_field() [OK]
Hint: Use have_rows() and the_row() to loop repeater fields [OK]
Common Mistakes:
  • Using foreach on get_field() without have_rows()
  • Missing the_row() call inside loop
  • Not accessing image url from array
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard