Support

Account

Forum Replies Created

  • Okay nevermind, it works with “Label” if I change the url to “?converted_classes=[label]” instead of using the value in the url.

    However, it’s only working for the first selection. For example, if a post has both the classes “Class_A” and “Class_B”, then only “?converted_classes=class_a” works.

    EDIT: I just noticed, looking down at the default WP custom fields section on the page after I save/update, that it’s only adding a meta value for the first one. So if I select “Class_A” and “Class_B”, it’s not even adding the meta value for “Class_B”.

  • Okay, it’s working almost the way it should. It’s only working if I have the Select field set to return “Values” and not “Labels”.

    I can, however, get it to work with “Labels” if I change a line to
    $values = get_field('classes', $post_id, false);
    But then it only shows one result at a time. Like if multiple posts have a class value of “8”, it’s only displaying one.

  • Where exactly do I put that in my current code? I tried adding it but it gave me a 500 error.

  • I changed “[‘fields’]” to “[‘acf’]” and also updated the “[‘field_590cecb75ba1b’]” to the new ID. Somehow that made the URL work when creating a post, but it’s still not actually saving a title.

  • I’m having the same issue. It was working perfectly fine in v4, but something has broken in v5.

    This is my code on my page template to show the form:

    
    <?php acf_form(array(
          'field_groups' => array('group_59398ef696c50'),
      		'post_id'		=> 'new_universe',
      		'post_title'	=> false,
      		'post_content'	=> false,
      		'new_post'		=> array(
      			'post_type'		=> 'universe',
      			'post_status'	=> 'publish'
      		),
          'submit_value' => 'Create'
    		)); ?>
    

    and this is my pre_save_post function

    
    function create_universe_form( $post_id ) {
      // bail early if not a new post
      if( $post_id !== 'new_universe' ) {
        return $post_id;
      }
      // vars
      $title = $_POST['acf']['field_59398f1d71f62'];
      // Create a new post
      $post = array(
        'post_status'	=> 'publish',
        'post_type'		=> 'universe',
        'post_title'	=> $_POST['acf']['field_59398f1d71f62'],
      );
      // insert the post
      $post_id = wp_insert_post( $post );
      // Update $_POST Return
      $url = get_permalink($post_id);
    	$_POST['return'] = ($url);
      // return the new ID
      return $post_id;
    }
    
    add_filter('acf/pre_save_post' , 'create_universe_form', 1, 1 );
    

    Currently, it is properly saving/updating the URL/slug, but not the actual title.

  • Yeah I couldn’t quite get that to work. I did play around some more with meta_query and I’m almost there. This is my current code:

    
    <div id="lorebook-archives">
        <?php // Only Show Current User's Posts
          if ( is_user_logged_in() ):
            global $current_user;
        wp_get_current_user();
    
        $universe = get_field('universe-selector');
    
        $author_query = array(
          'posts_per_page' => '-1',
          'author' => $current_user->ID,
          'post_type' => 'location',
          'meta_query' => array(
            array(
              'key' => 'location-universe',
              'value' => $universe
            )
          )
        );
    
        $author_posts = new WP_Query($author_query);
        while($author_posts->have_posts()) : $author_posts->the_post();
        ?>
    
          <?php
          $bg = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), 'full' );
          ?>
    
            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
              <div id="archive-post" style="background: url('<?php echo $bg[0]; ?>') repeat center center #fbfbfb; background-size:cover;">
                <h1><?php the_title(); ?></h1>
              </div>
            </a>
    
        <?php
        endwhile;
      endif; ?>
    
      </div>
    

    I have a Post Object custom field on my page called “universe-selector”. I’m using this as a variable for the value of the “location-universe” field on the individual posts.

    I can’t get this to work with a Post Object field, though. I DID get it to work with a Relationship Field, by setting the Return Format to Post ID. But that option doesn’t seem to be available for Post Object fields, at least not in the free ACF v4. Is there any way I can get the Post ID from the Post Object field without requiring ACF Pro?

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