Support

Account

Forum Replies Created

  • Working, thank you James!

  • Yes!, how do I close as resolved the thread ?

  • Oh I just realize
    the compare should be ‘LIKE’ I had ‘=’

       array(
                                        'key' => 'cobertura_%_pais',
                                        'value' => '"'.$pais.'"',
                                        'compare' => 'LIKE'
                                    )
  • I doesnt work if I remove this a:1:{i:0;s:4:

    Its working like this:
    'value' => 'a:1:{i:0;s:4:"'.$pais.'";}',

    Thank you very much!

  • Finally I looks that its working like:

    $args = array(
      'numberposts' => -1,
      'post_type'   => 'noticias',
      'meta_query'  => array(
    
        array(
          'key'   => 'cobertura_%_pais',
          'compare' => '=',
          'value'   => 'a:1:{i:0;s:4:"'.$pais.'";}',
        )
    
      )
    );

    Is that ok?

  • I think Im getting there I know:

    $where = str_replace("meta_key = 'cobertura_%", "meta_key LIKE 'cobertura_%", $where);

    I have

     'key'   => 'cobertura_%_pais',
          'compare' => '=',
          'value'   => '5443',

    Just need the value for value => ” because in te DB the value is
    “a:1:{i:0;s:4:”5443″;}”

  • Great James I have a light. I did it good with a checkbox with fixed values but my sub fields are getting the values from a custom post type
    How do I know the values saved for the sub fields in my repeater?, I notice that the key is increasing each time I save a sub field value for country
    ie (location_1_country, location_2_country, location_1_country…) And the value saved is something like: i:0;s:4:”5446″; where I check that 5446 is the ID of the country, also it creates another key: _location_1_country, in this case the value is field_576d3054bcc34 but have no idea where it comes from. So my problem is How do I get only the “5446” from the i:0;s:4:”5446″; and where do I look for the _location_1_country value?
    Pleae be patient Im not a programmer, but a wordpress enthusiastic!

  • It works great, thank you very much!!!!
    Best regards
    V

  • Ok I fixed this way, getting the subfields separated

    <?php if( have_rows('temas') ) { ?>
    <p class="font-arial fs-13 hint-text">Tema(s) general(es)<br><strong>
        <?php while( have_rows('temas') ): the_row(); ?>
            <?php $post_object = get_sub_field('tema_general'); ?>
            <?php if( $post_object ): ?>
                <?php // override $post
                $post = $post_object;
                setup_postdata( $post );
                ?>
                <li><?php the_title(); ?></li>
                <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
            <?php endif; ?>
        <?php endwhile; ?>
        <?php echo "</strong></p>"; ?>
    <?php } ?>
    
    <?php if( have_rows('temas') ) { ?>
    <p class="font-arial fs-13 hint-text">Tema(s) especifico(s)<br><strong>
        <?php while( have_rows('temas') ): the_row(); ?>
            <?php $post_object = get_sub_field('tema_especifico'); ?>
            <?php if( $post_object ): ?>
                <?php // override $post
                $post = $post_object;
                setup_postdata( $post );
                ?>
                <li><?php the_title(); ?></li>
                <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
            <?php endif; ?>
        <?php endwhile; ?>
        <?php echo "</strong></p>"; ?>
    <?php } else {  if ($tg != '') { ?><p class="font-arial fs-13 hint-text">Temática general <br><strong><?php echo $tg; ?></strong></p><?php } 
     if ($te != '') { ?><p class="font-arial fs-13 hint-text">Temática específica<br><strong><?php echo $te; ?></strong></p><?php }
    } ?>

    Now I want to echo the label Tema(s) especific(os) and Tema(s) general(es) only if a specific sub field exist, since now is printing in the case if any of the 2 subfields exists, thank you!

  • Hi John, I got working the first loop, now Im getting the values for the “temas” but theres printing another value duplicated by 3 on each subfield right next to “temas_generales” and “temas_especificos”. I dont know where is coming from, here is the code (sorry for just pasting the code before)

    “temas” is a repeater that has 2 subfields “tema_general” and “tema_especifico” both are Post Object defined as Post Object in the Return Format field

    if( have_rows('cobertura') ): ?> 
    <p class="font-arial fs-13 hint-text">País(es)<br><strong>
    <?php while ( have_rows('cobertura') ) : the_row(); 
    $myposts = get_sub_field('pais');
    if( $myposts ):  foreach( $myposts as $post_object):
       echo get_the_title($post_object->ID); 
    endforeach; 
      endif;
      echo "</strong></p>";
          endwhile;
        else :   
          if ($pais != '') { ?><p class="font-arial fs-13 hint-text">País<br><strong><?php echo $pais; ?></strong></p><?php } 
        endif;  
    
        
    if( have_rows('temas') ):  ?>
    <p class="font-arial fs-13 hint-text">Tema(s)<br><strong>
    <?php   while ( have_rows('temas') ) : the_row(); 
    
    $post_objects = get_sub_field('tema_general');
    
    if( $post_objects ): ?>
        
        <?php foreach( $post_objects as $post): // variable must be called $post (IMPORTANT) ?>
            <?php setup_postdata($post); ?>
          
                <?php the_title(); ?>
               
           
      <?php endforeach; ?>
        
        <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    <?php endif;
    
    $post_objects = get_sub_field('tema_especifico');
    
    if( $post_objects ): ?>
        
        <?php foreach( $post_objects as $post): // variable must be called $post (IMPORTANT) ?>
            <?php setup_postdata($post); ?>
          
                <?php the_title(); ?>
               
           
      <?php endforeach; ?>
        
        <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    <?php endif;
      echo "</strong></p>";
    
       endwhile;
        else :   
    
        endif;  ?>
  • They are post objets, I just fixed those:

    if( have_rows(‘cobertura’) ): ?>
    <p class=”font-arial fs-13 hint-text”>País<br>
    <?php while ( have_rows(‘cobertura’) ) : the_row();
    $myposts = get_sub_field(‘pais’);
    if( $myposts ): foreach( $myposts as $post_object):
    echo get_the_title($post_object->ID);
    endforeach;
    endif;
    echo “
    </p>”;
    endwhile;
    else :
    if ($pais != ”) { ?><p class=”font-arial fs-13 hint-text”>País<br><?php echo $pais; ?></p><?php }
    endif; ?>

    Now I have another repeater “temas” located right next to “cobertura” from where I get “temas_generales” and “temas_específicos” both are post object subfields, I did copy & paste the code for “cobertura” and change only the names of the fields, but it returns the title of the custom post type (news), any idea?

  • I tried with text subfield and it is working but not with the post objet subfields

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