Support

Account

Forum Replies Created

  • hi @unomobil

    i guess you should note what are you doing and what field type are you trying to get.

    but the most usual code to get field’s values is:
    the_field( 'field_name', false, false )

    false, false make ACF to get values from THIS POST. btw you can use $post->ID instead them.

    i guess you know these codes are php codes and you should use <?php and ?> before and after them.

    Hope this help
    A

  • Hi @john.marcello

    a boolean function return true or false. so a true / false checkbox return true or false too.

    this code should resolve your problem:
    target="<?php echo get_field( 'open_where', false, false ) == true ? '_blank' : '_self'; ?>"

    so your <a> link’s code should looks like this:
    <a target="<?php echo get_field( 'open_where', false, false ) == true ? '_blank' : '_self'; ?>" href="<?php the_sub_field('video_thumbnail_link'); ?>">

    hope this help you
    A

  • Hi @elliot

    Yes. i’m getting the values of current post’s checkbox via get_field, and i’m trying to find any pages which have any of current checkbox values.
    as i said, i’m trying to create something like ‘related post’ but via ACF checkbox.

    i’m not sure how i should dynamically generate the meta_query args array.

    i tried this code:

    	$checkbox_field = get_field( 'checkbox_field', $post->ID );
    	$args = array(
    		'post_type'				=> 'page',
    		'post__not_in'			=> array( $post->ID ),
    		'posts_per_page'		=> $related_no,
    		'meta_query'			=> array(
    			'relation'		=> 'OR',
    			array(
    				'key'		=> 'checkbox_field',
    				'value'		=>	$checkbox_field ,
    				'compare'	=>	'IN'
    				)
    			)
    		);

    didn’t worked.
    removing ‘relation’ => ‘AND’, adding meta_key does not have any effect on result.

    i searched whole google, but didn’t find any solution for my problem. how i should do that :S

    Thanks,
    A

  • hi @Chris

    use the full parameters for your get_field, means:
    $related_1 = get_field( '1_related_product', false, false );
    this make ACF get the values from this post.

    and as @Elliot said, use:
    echo get_the_post_thumbnail( $related_1, 'thumbnail' ); to echo the image size you want.

    let me know anything happened.
    A

  • hi @kiouv

    if your field return an array it’s because you set it to return an array.
    on the ACF image field settings there is an option that you can change its returnable value.

    go to the image field and take a look there, you will find your answer. you should set it to return image URL. so your code should be like this in your template:
    <img src="<?php the_field( 'image_field_name' ); ?>" />

    to get image dimensions, title, caption, description you should go a little more advanced.

    let’s get the things we need:

    $image_dimensions = wp_get_attachment_image_src( get_field( 'image_field_name', false, false ), 'full' );
    $image_meta = get_post( get_field( 'image_field_name', false, false ) );
    $image_alt = get_post_meta( $image_meta->ID, '_wp_attachment_image_alt', true );

    full‘ => it define the image size. EX: full, thumbnail, small, … ( it’s in your theme function and could be more )

    _wp_attachment_image_alt‘ => it get image alt, the italic part could be caption, description.

    so your template code should looks like this:
    <img src="<?php the_field( 'image_field_name' ); ?>" alt="<?php echo $image_alt; ?>" width="<?php echo $image_dimensions[1]; ?>" height="<?php echo $image_dimensions[2]; ?>" />

    hope it could help you.
    thanks,
    A

  • Hi @elliot

    Thanks for responding.
    actually i code it before opening this support thread. my code is almost same as the above thread you linked but my problem is it’s not working with multiple values. means when the page / post contain multiple values ( actually it’s an array of values ) the relation code not working, and the above code is working only with two values but what if i have more than two values ?

    i have an ACF checkbox with many values ( like value1, value2, value3, … , value10 ). the above code may works fine for one or two value but how i should loop it to work with the array.

    also this is my code:

    	$checkbox_field = get_field( 'checkbox_field', $post->ID );
    	$checkbox_field_opts = implode( ", ", $checkbox_field);
    	$args = array(
    		'post_type'				=> 'page',
    		'post__not_in'			=> array( $post->ID ),
    		'posts_per_page'		=> $related_no,
    		'meta_query'			=> array(
    			'relation'		=> 'OR',
    			array(
    				'key'		=> 'checkbox_field',
    				'value'		=>	$checkbox_field_opts,
    				'compare'	=>	'LIKE'
    				)
    			)
    		);

    i tried to implode it, but that’s not working too.

    Thanks
    A

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