• Resolved scooterlord

    (@scooterlord)


    Hello and thank you for this wonderful plugin!

    I am trying to use ACF fields for the meta description using the following snippet:

    %customfield(classified_condition)%

    The ‘classified_condition’ field is a select that contains both label AND value (like label:value). I want to show the value, however, I see the label. Is there a way around this?

    Thanks for your time!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Rank Math SEO

    (@rankmath)

    Hello @scooterlord,

    Thank you for contacting the support and sorry for not following up quickly and any inconvenience that might have been caused due to that.

    The custom field variable will not work on the ACF fields because of the way ACF stores values in the post meta table.

    They store values in a serialized format for groups and for other fields they store key-value pair.

    You can register a new variable using the following filter to get the value from the ACF field:
    https://rankmath.com/kb/filters-hooks-api-developer/#add-extra-variables

    This is how we register the WooCommerce variable in the Rank Math plugin:
    https://github.com/rankmath/seo-by-rank-math/blob/master/includes/modules/woocommerce/class-wc-vars.php#L24

    Hope that helps.

    Thread Starter scooterlord

    (@scooterlord)

    Hello and I also apologize for not replying any sooner.

    I can’t really understand what the suggestion is. Is it possible that you can elaborate with an example?

    Plugin Author Rank Math SEO

    (@rankmath)

    Hello @scooterlord

    Here’s the link to the example code:
    https://github.com/rankmath/seo-by-rank-math/blob/master/includes/modules/woocommerce/class-wc-vars.php#L24

    Here is the simplified version of the code:

    add_action( 'rank_math/vars/register_extra_replacements', function() {
        rank_math_register_var_replacement(
    		'acf_field_variable',
    		[
    			'name'        => esc_html__( 'Variable Name.', 'rank-math' ),
    			'description' => esc_html__( 'Variable Description.', 'rank-math' ),
    			'variable'    => 'acf_field_variable',
    			'example'     => get_acf_field_value(),
    		],
    		'get_acf_field_value'
    	);
    } );
    function get_acf_field_value() {
    	global $post;
    	return get_field( 'acf_field_key', $post->ID );
    }

    In the Variable dropdown, you will see the variable name after adding the filter code.

    In the above code, the variable dropdown will show %acf_field_variable%

    If you are still unsure, we would recommend hiring a freelancer or a developer to help you with the code.

    Hope that helps. Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘ACF select values’ is closed to new replies.