Support

Account

Forum Replies Created

  • *SOLVED* (my bad!)

    DOH – it seems that it does not like this function:

    /*Function to defer or asynchronously load scripts*/
    function js_async_attr($tag){
    
    # Do not add defer or async attribute to these scripts
    $scripts_to_exclude = array();
    
    foreach($scripts_to_exclude as $exclude_script){
     if(true == strpos($tag, $exclude_script ) )
     return $tag;
    }
    
    # Defer or async all remaining scripts not excluded above
    return str_replace( ' src', ' defer="defer" src', $tag );
    }
    add_filter( 'script_loader_tag', 'js_async_attr', 10 );
  • Thank you so much, John – you are a star! It works 🙂

  • Hi John

    Thank you so much for your time and effort.

    I’m getting a time-out. I think it is pulling to many posts.
    Thought about adding a query (the page is a custom post type), but now i’m getting an error message.

    Warning: htmlspecialchars() expects parameter 1 to be string, object given

    function my_acf_load_value($value, $post_id, $field) {
    $query = new WP_Query( array( 'post_type' => 'artikler', 'posts_per_page' => 1, ) );
    return $query;
    
      if ($query->have_rows('artikel', $post_id)) {
        while ($query->have_rows('artikel', $post_id)) {
          $post_object_id = get_sub_field('artikel_navn', false);
          $values = get_field('tekst', $post_object_id);
        }
        $value = implode(', ', $values);
      }
      return $value;
    }
    add_filter('acf/update_value/name=meta_beskrivelse', 'my_acf_load_value', 10, 3);
  • @John thank you so much for all your effort. I tried your solution, and some others – and finally it worked. It seems that the main error was that reset_postdata was used on the wrong loop. So here is the code that is working

    <?php
    	$thistitle = get_the_title();
    	$args = array( 'post_type' => 'navigation', 'pagename' => 'Top navigation' );
    	$loop = new WP_Query( $args );
    
    	while ( $loop->have_posts() ) : $loop->the_post();
    
    	if ( have_rows('navigation') ):
    	    while ( have_rows('navigation') ) : the_row();
    			if ( get_sub_field('mega_menu_active')) {
    
    				$navitemID = get_sub_field('masterside', false, false);
    
    					$subargs = array( 'post_type' => 'navigation', 'page_id' => $navitemID);
    					$subloop = new WP_Query( $subargs );
    
    					while ( $subloop->have_posts()) : $subloop->the_post();
    				        if( have_rows('mega_menu')):
    				            while (have_rows('mega_menu')) : the_row();
    				              echo get_sub_field('menu_overskrift');
    				                while (have_rows('mastersidelinks')) : the_row();
    				                  $subnavitemID = get_sub_field('masterside_sub_links', false, false);
    				                  echo get_the_title($subnavitemID);													echo get_the_permalink($subnavitemID);
    				                endwhile;
    												
    			              endwhile;
    				        endif;
    							$loop->reset_postdata();
    					endwhile;
    				} else {
    					include(locate_template('templates/navigation/navigation-top.php'));
    				}
    	    	endwhile; else : endif; endwhile;
    	?>
  • I had the same problem. It turned out to be an outdated version of Visual Composer, that was making the conflict.

  • @John ….that is probably the best way – to wait for 4.7.

    Thanks for your reply

  • Hi John

    Thank you for your answer.

    I deleted the repeater fields, and made new ones – that fixed it.
    That could have saved me some hours doing that earlier 🙂

    Cheers
    Kris

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