Support

Account

Forum Replies Created

  • sounds like you have a similar question but not quite mine. Start a new one and tag me in it, show me the actual error and your actual post type name when you do!!

  • Thanks for looking. I appreciate it. MERRY CHRISTMAS TOO!

  • Thanks John! That’s exactly what I was considering. It seems repeaters are an amazing tool to simplify and make easier some interactions, but in the long run CPT will offer more flexibility.

  • In the first section of code I was using $pdf->WriteHTML( $kid['name'] ); //does NOT SHOW

    to pull the array.

    The section section instead of pulling code I was just testing to see if it would output anything. So the “if” statement would return the string “a kid” for each subfield with content. (it’s not returning actual content).

  • The ACF fields are outsite the_content() value. you should try using acf-format_value.

    There is a great example here:
    https://www.advancedcustomfields.com/resources/acf-format_value/

  • The problem with random queries is that they are highly memory intensive.

    Your code above will load the image, but will your server allow rand()? that would be the first question. Many hosting providers will not allow it. If it WILL allow, then i’ll try to help you with the actual code.

  • This is how I got it to work, but it seems there should be an easier way?

    $event_query = new WP_Query(     
        array(
            'post_type' => 'al_event',
            'orderby' => 'menu_order',
            'order' => 'ASC',
            'meta_query' => array(
                array(
                    'key'     => 'event_date_end',
                    'compare' => '>=',
                    'value'   => $today,
                ),
                array(
                    'key'     => 'event_date',
                    'compare' => '<=',
                    'value'   => $future,
                ),
                array(
                    'relation' => 'OR',
                    array(
                        'key' => 'hide_on_public_page',
                        'value' => '0'
                    ),
                    array(
                        'key' => 'hide_on_public_page',
                        'compare' => 'NOT EXISTS', 
                    )
                )
            ),
        ) );
  • I’ve created a group (called ‘ce_hours’). It has 3 subfields (lt, nav, lvtlvp) all of which are numbers.

    This is my code for viewing the the array:

    if ( have_rows('ce_hours') ){
        echo '<h2>there are rows in the hours</h2>';
        echo '<pre>'.print_r(ce_hours).'</pre>';
    }else {
        echo 'no rows';
    }

    If I load this on a page before adding the fields then it echo’s no rows. However if I save the page then the field holds rows and my print_r states “1”.

    I’ve tried to test this by having a page open and going to my acf dashboard and copying my group (ce_hours to ce_hours_copy).

    I then add this to my page content:

    if ( have_rows('ce_hours_copy') ){
        echo '<h2>there are rows in the hours copy</h2>';
        echo '<pre>'.print_r(ce_hours_copy).'</pre>';
    }else {
        echo 'no rows';
    }

    If I reload the page then I get “there are rows in the hours”

    1

    “.
    Now if I edit the page and click update (no other changes) then when I reload that page again I get
    “there are rows in the hours”

    1

    “.
    “there are rows in the hours copy”

    1

    “.

    SO for some reason it’s adding rows even though I don’t want it to. In the end I want to add a title if there are any rows, so I need the conditional to work. Here is my prod code I intend to use:

    if ( have_rows('ce_hours') ){
        echo '<h2>Credit Hours</h2>';
        while ( have_rows ('ce_hours') ) : the_row();        
                echo '<ul>';
                if (get_sub_field('rn_hours')) echo '<li>'.get_sub_field('rn_hours').' credit hours for RNs</li>';
                if (get_sub_field('nab_hours')) echo '<li>'.get_sub_field('nab_hours').' credit hours for NABs</li>';
                if (get_sub_field('lvnlpn_hours')) echo '<li>'.get_sub_field('lvnlpn_hours').' credit hours for LVN/LPNs</li>';
                echo '</ul>';
        endwhile;
    }
  • that’s the main plugin, but then you need to install the extension: https://wordpress.org/plugins/ajax-load-more-for-acf/

  • John, thanks for sending that option. I saw it too but it has not been updated in over a year. I tend to also agree, it’s doing a lot when I only need a little. I’m going to keep searching for something a bit more bespoke.

    BTW thanks for all you do with this plugin! I couldn’t do what I do without it!

  • I’d love this if it’s possible!

  • Yeah, I guess I could have been more clear on that. I got it to work this way:

    function populate_cpt_titles( $form ) {
    	foreach ( $form['fields'] as $field ) {
    		if ( $field->type != 'select' || strpos( $field->cssClass, 'populate_al_products' ) === false ) {
    	    		continue;
    		}
    
    		$field->placeholder = 'Select an your product';
    
    		$args = [
    			'posts_per_page'   => -1,
    			'order'            => 'ASC',
    			'orderby'          => 'post_title',
    			'post_type'        => 'al_product', 
    			'post_status'      => 'publish',
    		];
    		$custom_posts = get_posts( $args );
    
    		$options = [];
    		foreach( $custom_posts as $custom_post ) {
    			$options[] = ['text' => $custom_post->post_title, 'value' => $custom_post->post_title];
    
                $subfields = get_field('product_variations', $custom_post->ID);
    			if ($subfields) {
                    foreach ($subfields as $subfield) {
                        $options[] = ['text' => $subfield['part_number'], 'value' => $subfield['part_number'] ];
                    }
                }
    		}
    
    		$field->choices = $options;
    	}
    	return $form;
    }
  • I’m in fact trying to get the actual variations.
    so if i have a product set like this:

    Product A
    variation – 001
    variatin – 002
    variation – 003

    Product B
    variation – 123
    variation – 124
    variation – 125

    I want to have an array that shows

    product a, 001, 002, 003, product b, 123, 124, 125

  • I have 284 products and I’d like to add data to the repeater fields. anywhere from 5 to 12 repeater lines. Do are there any samples of something similar to get me started?

    Thanks!

  • this makes sense, but the videos are from youtube and don’t have sound.

  • just tried with your code on my server and my api key and it’s working fine.

    A couple questions. Are you using a child theme?

    On google’s site it says:

    If you are loading Maps JavaScript API from the deprecated v2 path, you will get the NoApiKeys warning, even if you specified the key parameter. Please check the v2 to v3 upgrade guide and migrate your application to Maps JavaScript API v3.

    Maybe try a new API key?

  • You could try mine I guess…

    function rt_load_plugin_css () {
    	$mapkey;  //replace variable with your actual ke
    	$mapkeyurl = 'https://maps.googleapis.com/maps/api/js?key='.$mapkey;
    	$dir_url = get_template_directory_uri() . '/js/acf-map.js';
    
    	wp_enqueue_script( 'map_script', $dir_url, array('jquery'), '1.0', true );
        	wp_enqueue_script( 'googlemap', $mapkeyurl, true);
    }
    add_action ('wp_enqueue_scripts', 'rt_load_plugin_css');
  • You actually have a key there right? I’m assuming you just removed it for the purpose of the question?

  • You have a typo. You spelled enqueue wrong on the add action line for your function name. I usually add “true” to the google-map script as well.

  • Thanks John! Can you explain why this works? Or point me in a research direction?

  • Here’s what I did: (in the plugin file that i use to create my custom post type)

    add_filter( 'manage_speakerCPT_posts_columns', 'my_columns_filter', 10, 1 );
    function my_columns_filter( $columns ) {
     	$column_thumbnail = array( 'thumbnail' => 'Speaker Image' );
    	
            //these 2 lines if you want the photo in front
    	//$columns = array_slice( $columns, 0, 1, true ) + $column_thumbnail + array_slice( $columns, 1, NULL, true );
    	//return $columns;
    
            //this line if you want the photo at the end.
    	return array_merge ( $columns, $column_thumbnail );
    }
    add_action( 'manage_speakerCPT_posts_custom_column', 'my_column_action', 10, 1 );
    function my_column_action( $column ) {
    	global $post;
    	$speaker_pic = get_field('speaker_photo');
    	switch ( $column ) {
    		case 'thumbnail':
    			echo '<img src="' . $speaker_pic . '" width="100" />';
    			break;
    	}
    }

    In the above code for the filter and action my CPT is called speakerCPT, so replace that with your CPT name.
    In the action function, $speaker_pic sets my variable for the ACF field ‘speaker_photo’. which is an image field returning only the url.

    Notice I have a commented out line in the first function. I didn’t know if you wanted the image as the first column or the last so you can choose by changing comments. Right now, photo will appear at the end. DON’T do BOTH.

  • What I had isn’t working. It brings merges the relationship fields, but doesn’t sort them as if it were one array. it presents contents of the first and then the contents of the 2nd. any wise words for me?

  • well actually that seemed to work, but I had to use:

        $speakers = array_merge(
             get_field('relationship_1'),
             get_field('relationship_2'));

    instead of:

        $speakers = array_merge(
             get_field('relationship_1', false, false),
             get_field('relationship_2', false, false));
Viewing 25 posts - 1 through 25 (of 46 total)