Support

Account

Forum Replies Created

  • Hi @andremacola

    That’s a good solution too, and probably more efficient than querying with a regex.

    I don’t see REGEXP in the WP codex, but it’s available. Looks like they added it within the past year, so perhaps it hasn’t made the docs yet. I’m running WP 3.9.2.

    Cheers

  • @andremacola

    I achieved this in a meta_query by using REGEXP. I couldn’t find a way to do it with just dates and a range, because like you I wanted it to be year-agnostic.

    The date format by default is stored as YYYYMMDD. The following searches for a string like $$$$MM$$, where MM is your month. In other words, any 4 digits, followed by a specified 2-digit month, followed by any 2 digits.

    $filter_month = '09'; // show september only
    
    $args = array (
      'post_type'      => 'course',       // your custom post type
      'meta_key'       => 'course_date',  // your custom date field name
      'orderby'        => 'meta_value_num',
      'order'          => 'ASC',
      'meta_query' => array(
        array(
          'key'      => 'course_date',
          'compare'  => 'REGEXP',
          'value'    => '[0-9]{4}' . $filter_month . '[0-9]{2}',
        ),    
      )
    );
    
    $posts = get_posts($args);
    

    A little late, but hope this helps.

  • Ah I see. For my image field, I have the Return Value set to Image Object. So I could set it to Image ID if I wanted and not have to tack on [‘id’] per my code above.

  • I had to add [‘id’] to the end of get_field in order to get it to work.

    <?php 
    $profile_pic = wp_get_attachment_image_src(get_field('profile_pic')['id'], 'profile-thumb');
    ?>
    
    <img src="<?php echo $profile_pic[0]; ?>" />

    get_field seems to return an array and not the id.

    Thanks for this AMAZING plugin btw!

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