Support

Account

Forum Replies Created

  • Yes, you can do this. There are plugins that can assist like FacetWP, WP Gridbuilder, Search & Filter Pro, and others. Most WordPress filtering plugins integrate with ACF.

  • You could do something like:

    $value = get_field('text_field');
    
    if( $value && $value != 'Do Not Show' ) {
      echo $value;
    }
  • Group fields append the group name to the meta key. You can browse the wp_usermeta table (or its equivalent if wp_ isn’t your database prefix) in your WordPress database to see your user-based group fields and their values if you’ve populated any but the meta key is usually: group_name_subfield_name.

  • You need to define the meta key to be used to order by, this is different than the meta_query. The easiest way to do this would be to add a ‘meta_key’ => ‘personnel_company’ to your query args (separate from the meta query.)

  • I don’t use Elementor but do they support shortcodes in their content? ACF has a built-in shortcode for display of their fields, which you can read more on here.

  • You can modify the relationship field’s query with this ACF filter.

    It’s been awhile since I’ve worked with The Events Calendar but it’d likely be something comparable to:

    // change relationship field name in filter
    add_filter('acf/fields/relationship/query/name=your_relationship_field_name', 'prefix_events_relationship_query', 10, 3);
    function prefix_events_relationship_query( $args, $field, $post_id ) { 
        $today = date('Y-m-d');
    
        $args['meta_query'] = array(
          array(
            'key' => '_EventStartDate',
            'value' => $today,
            'compare' => '>=',
          )
        );
    
        return $args;
    }

    You may need to adjust the start date custom field name or the date format of today’s date but this is the general direction you’d head.

  • You may want to refer to the ACF article on querying relationship fields.

    Relationship fields are storing an array of data, not names of items selected, so you’re usually finding them by ID. I’d find the ID of branding then adjust your query to something like:

    $brandingID = X; // replace X with the post ID of branding
    $case_args = array( 
        'post_type' => 'cases', 
        'posts_per_page' => -1, 
        'orderby' => 'menu_order', 
        'order' => 'ASC',
        'meta_query' => array(
          array(
            'key' => 'work',
            'value' => '"' . $brandingID . '"',
            'compare' => 'LIKE'
          )
        )
     );

    Depending on where you’re using these types of queries, you may want to adjust $brandingID in the query to something like a get_the_ID() call if you’re putting this query on each work post type as you’d understandably not want to hard code an ID in that type of instance and you’d want the ID to instead just reflect whatever the post type is you’re viewing.

  • How are you pulling the field into the page? With a get_field or the_field call? Using something to help you do it?

    For an ACF field that gives you options on how to return a value like file and image, what gets stored in the database meta key is usually the ID. The choice on how you return the info only gets applied when using a the_field or get_field ACF call. So if you’re using something that is pulling custom fields with get_post_meta instead, that’s likely why you’re seeing the issue.

    Other times, I have seen ACF return a different value than what is selected before but usually toggling a different selection and saving then reselecting the alternative return value I want corrects it.

  • You don’t need a separate age field. You can do the calculation in the theme itself. Something like:

    <?php $DOB = get_field('date_of_birth'); // change for field name
    $birthday = new DateTime($DOB);
    $dateDiff = $birthday->diff(new DateTime);
    echo $dateDiff->y.' years old';
    ?>
  • Why do you want to use ACF to duplicate this info? WooCommerce stores that data in meta key/value pairs already. For instance, you can access length with something like:

    <?php echo get_post_meta($post->ID, '_length', true); ?>

  • You could create this as a custom ACF block called preamble or similar. When registering the ACF block, within its block.json file, you can put “multiple”: false in the supports section to limit it to only being used once.

    Additionally, you can set ‘jsx’ to true to make the block reliant on InnerBlocks. InnerBlocks work like native blocks where you edit like normal, not via ACF fields. I would personally also limit the allowedBlocks for InnerBlocks to just the core/paragraph block, as well.

    So your block.json would look something like this:

    {
        "name": "preamble",
        "title": "Preamble",
        "description": "A styled post preamble paragraph.",
        "category": "formatting",
        "acf": {
            "mode": "preview",
            "renderTemplate": "blocks/preamble/preamble.php"
        },
        "supports": {
            "multiple": false,
            "jsx": true
        }
    }

    Then your preamble block code would include something like:

    <?php $allowedBlocks = array(
      'core/paragraph'
    ); ?>
    <InnerBlocks allowedBlocks="<?php echo esc_attr(wp_json_encode($allowedBlocks)); ?>" />

    It wouldn’t force it to be the first block, but you could probably do that utilizing something like block templates.

  • You have a repeater nested within an ACF flexible content field so where get_sub_field is looking for data is changing based on where you’re placing it.

    Ex: when you put it ABOVE the slider repeater, it’s looking for the image field in the flexible content area. When you put it after the loop for your repeater, it’s looking for the image field as a subfield of “slider”. That’s why it’s returning null when you move where it’s located.

    If you want to use a field assigned to the flexible content layout inside of the nested repeater, your best bet would be likely to assign it to a variable ahead of opening your slider repeater loop so leave the $image variable where it is in your working example and then reference that variable within your slider repeater loop.

  • It wouldn’t be in the wp_options table. If you attach a field to a taxonomy term, it would be in the wp_termmeta table for that term. It would be the name of your field in the termmeta attached to the shows taxonomy term you adjusted the actors field for.

    Also the field in the database does not include the term-slug_term-id. It’s just the info you pass to the get_field ACF function to know where to find your ACF field’s data.

  • On your taxonomy archive, you’re not referencing your shows taxonomy in the get_field call for actors. So instead of just:

    <?php $get_actors = get_field('actors'); ?>

    This needs to be something like:

    <?php $get_actors = get_field('actors','shows_'. get_queried_object()->term_id); ?>

    You may need to edit the above if shows is your taxonomy slug for the taxonomy you attached the actors ACF field to. You just need a reference in that call to the term you’re pulling this data from and that’s placed in the get_field call as the second argument in the form of term-slug_term-id.

  • If actors is attached to a taxonomy, you need to reference the taxonomy in the get_field call for it. So it might be something like:

    get_field('actors','taxonomy_name_X');

    Where X is the ID of the taxonomy.

  • Don’t think the filter param exists anymore. Also, the REST API doesn’t support the same orderby parameters as a regular WP query. It supports author, date, id, include, modified, parent, relevance, slug, include_slugs, title.

    You likely would have better luck using something like rest_{$this->post_type}_query.

  • The way nested repeaters in a group field stores its subfield values is:

    group_name_repeater_name_X_repeater_subfield

    Where X is the repeater row and it increments starting at 0 so if you had a field called name in your book videos nested repeater, if any post had a value there, it would be at:

    book_videos_bk_videos_0_name

    That being said, you could adjust your meta_query to just query if that key exists, you don’t need to check if the group exists, as well. You’d just grab every post that has something in the first repeater spot for any required subfield value of the repeater. Does that make sense?

  • Your opening of the main while loop where your comment is “the loop that refuses to go anywhere”, when you’re moving it, are you also moving its closing statements? That should go after your opening:

    if ( have_posts() ) : while (have_posts()) : the_post();

    However, if you’re doing this but not also moving one of your endwhiles to in front of the closing endif then it would cause problems. I would check your endwhile and your endif statements and make sure they’re all lining up with the if and while statements.

  • Repeaters are stored in the format:

    repeater_name_X_sub_field

    Where X is the row number and it starts at 0. So the first row would be like repeater_name_0_sub_field, the next repeater_name_1_sub_field, etc.

    You can use that with get_post_meta to display a specific value, like:

    get_post_meta($post->ID,'repeater_name_0_sub_field',true);

    But depending on the field type you’re displaying, like if it’s something like an image or similar, that wouldn’t run it through ACF’s display process so you could have to do some work on your end there.

  • Multiple ways to do it but one way is with an incrementing variable. You would want to know how many items you have total, as you’re going to want to do splits at multiples of 4 when there are still more items to show, you wouldn’t want to do it after the 8th item when there’s only 8 items, for example.

    So something like this: https://pastebin.com/nK4rpV5T

    There could be other/better ways to go about it but it’s one way to achieve what you’re after.

  • I would try adding the post ID reference to the get_field calls in your function, like:

    function perf_pln2($post_id)
    {
    $total = (get_field('zip',$post_id)+get_field('kraken',$post_id))/(get_field('_price',$post_id)+0.01);
    $value = $total;
    $field_name = "perf";
    update_field($field_name,$value,$post_id);
    }
    add_action('save_post','perf_pln2');
  • For something like this, you’d want to reach out to the plugin you’re using to display the fields in Elementor to see if they provide a filter or something to change the separator when choosing multiple custom fields to display.

  • You could use a relationship field and set it up with the CPT. The documentation page on the field gives a code sample to loop through a list of posts selected with a relationship field.

Viewing 25 posts - 26 through 50 (of 71 total)