Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • @gregory @sherriff

    thanks for code, and for asking the question . I don’t get where this fits either

  • @jgregory – that’s sounds great. BUT – where would I put that? I rarely amend the WordPress admin side of things, so what .js file would that go in? Something along these lines? https://stackoverflow.com/questions/3326967/how-to-add-custom-javascript-to-wordpress-admin

  • I understand, that’s why I quoted ‘right way’. Because if prefer to do it as Eliot had in mind when he wrote the template for extensions but I don’t mind using it this way. I’m already happy it works ๐Ÿ™‚

    It just has me wondering why it doesn’t work, with the ‘default’ update value function.

    If you’re interested, you can testdrive the plugin (it’s on Github)… Always appreciate any input from other devs on it…

    I will open a new ticket… I wanted to already before I found this one ๐Ÿ™‚

  • Sometimes, the solution is lying right in front of you and is it better to replace instead of repair. I replace the query with the one from Query posts (now) and all is working as it should.

  • Yeah, that’s what I ended up doing to get the project wrapped today.

    I did a quick grab and dump of get_post_meta() to the error log from within my acf/save_post function, then watched it to see which of the many variables was the one acf was actually using. I realized I’d need to do that after I noticed moving fields into a new group for an existing custom post doesn’t actually clean up any of the old post_meta values– it just leaves the old post_metas there, creates new ones and starts using them. I think it may even have left/used the same ACF key_hashvalue in there, so now it appears twice in the post_meta (one of the reasons I was concerned about just using update_post_meta and similar WP functions instead of leveraging an ACF function to manage grouped fields).

    By the way, in case anyone else runs into this, @keithlock is spot on. ACF, when creating page_metas for groups, does so in the format:

    group_pretty_name . “_” . field_pretty_name

    In case anyone else runs into this problem and wants to dump stuff to the log to watch what’s going on during your custom function hooked in to acf/save_post, I found this little snippet super helpful (wish I had recorded what site/who I grabbed it from, but in my rush to solve this problem I forgot to — needless to say, not my original code solution here ๐Ÿ˜‰

    error_log(“Meta values of post:”);
    ob_start();
    var_dump(get_post_meta($post_id));
    error_log(ob_get_clean());

    Since all this stuff is happening at a point you can’t just echo the returned value of a get_post_meta() var_dump to the screen, I had to look up that little gem to get the var_dump into the log.

    The value does get dumped as one long string, but if you bring it into regular expression compliant application like notepad++, you can do a reg ex find/replace for \\n to \r\n and quickly have a human readable dump of the page_meta to scan and find what ACF is doing where.

    Updating the post_meta value directly is currently working fine (so far as I can tell– I have my acf/save add_action priority set to the suggested level of 20… doing it at other priority levels might cause some oddness…). But I’d much prefer an ACF native way of doing this, which so far as I can tell, doesn’t currently exist. I’m a little concerned about the direct update_post_meta (and in another location, delete_post_meta) that I’m using currently to work around this, since a quick google search of acf update_post_meta|delete_post_meta turns up all kinds of threads where people (and some acf support folks/devs) seem to be waiving everyone off from doing that, in favor of acf methods (a literal, archaic/original use of deprecation here? ๐Ÿ˜‰

  • where do I put these scripts?

    add_filter('acf/load_field/name=hidden_post_id', 'make_hidden_post_id_readonly');
    function make_field_readonly($field) {
      // sets readonly attribute for field
      $field['readonly'] = 1;
      return field;
    }
    
    add_filter('acf/load_value/name=hidden_post_id', 'set_hidden_post_id_value'), 10, 3);
    function set_hidden_post_id_value($value, $post_id, $field) {
      // set the value of the field to the current post id
      return $post_id;
    }
    
    add_action('admin_head', 'hide_hidden_post_id');
    function hide_hidden_post_id() {
      ?>
        <style type="text/css">
          /* the field key for the post id field */
          div[data-key="field_566aa87938bba"] {
            display: none;
          }
        </style>
      <?php 
    }
    
    add_filter('acf/validate_value/name=book_number', require_unique', 10, 4);
    function require_unique($valid, $value, $field, $input) {
      if (!$valid) {
        return $valid;
      }
      // get the post id
      // using field key of post id field
      $post_id = $_POST['acf']['field_566aa87938bba'];
      // query existing posts for matching value
      $args = array(
        'post_type' => 'post',
        'posts_per_page' = 1, // only need to see if there is 1
        'post_status' => 'publish, draft, trash',
        // don't include the current post
        'post__not_in' => array($post_id),
        'meta_query' => array(
          array(
            'key' => $field['book_number'],
            'value' => $value
          )
        )
      );
      $query = new WP_Query($args);
      if (count($query->posts)){
        $valid = 'This Value is not Unique';
      }
      return $valid;
    }
  • Actually, that begs a second question…

    I use some code to put ACF forms on the front side of the web site. So, which hook/filter do I use to load my JavaScript file and can I test to see if the form is on the front end or back end?

  • So this isn’t a full solution, but it at least allowed me to get the images from the custom image fields to display. Still seems to be a problem with YARPP but this seems to get by the problem at least for images.

    I noticed like you said that the image field was returning the ID of the image even though in my case I have it set to return the image URL to be used as a background image.

    I just fed that image ID into wp_get_attachement_url() and was able to use that url to display the image.

    <?php $imageId = get_field('post_featured_image');
    $imageUrl = wp_get_attachment_url($imageId); ?>
    	<a href="<?php the_permalink(); ?>">
    		<div class="relatedsingle" style="background-image: url('<?php echo $imageUrl; ?>');">
    			<div class="singleoverlaygreen"></div>
    			<h4><?php the_title(); ?></h4>
    		</div>
    	</a>

    This is obviously only to get the image url for a simple application like mine, but my guess is that you could use wp_get_attachment_metadata() instead of wp_get_attachment_url() to fetch anything from the image array that you would otherwise gotten from the ACF field.

  • Do you think it is possible to manipulate args directly with javascript with something like:

    jQuery('#acf-field-5923eb94b4a28').select2().val('some value').trigger('change');

  • Hello,

    As long as you have the field in question setup with ACF, you are set on that end of things.

    It’s then just a matter of displaying the correct data on the front-end to your Users, based on the date in that field (compared to today’s date).

    There are several ways to accomplish it… here are 2 ideas that came to me:

    1) Using PHP (probably the easiest)

    Here are the basic steps:

    a) Create an HTML/CSS template for what you want to accomplish. Something like below (based on your screenshot):

    
    <ul>
    <li><strong>Employment Status:</strong> <span style="color:green;">Current</a></li>
    <li><strong>This job will expire:</strong> December 25, 2017</li>
    </ul>
    

    b) Now, within your code, you will want to re-create the above dynamically. You can do something like (perhaps in a loop if you have multiple records to display):

    
    <?php
    $expiry_date = get_field('expiry_date');
    $is_expired = FALSE;
    $status_text = 'Current';
    $status_text_2 = 'This job will expire on:';
    $status_color = 'green';
    if ( strtotime(date('Y-m-d')) > date('Y-m-d', strtotime($expiry_date)) ) {
      $is_expired = TRUE;
      $status_text = 'Expired';
      $status_text_2 = 'This job expired on:';
      $status_color = 'red';
    }
    echo '<ul>';
    echo '<li><strong>Employment Status:</strong> <span style="color:' . $status_color . ';">' . $status_text . '</a></li>';
    echo '<li><strong>' . $status_text_2 . '</strong> ' . date("F j, Y", strtotime($expiry_date)) . '</li>';
    echo '</ul>';
    ?>
    

    Resources:

    2) Using vanilla JavaScript (or JQuery).

    Here are the basic steps:

    a) Print the expiration date to the page, perhaps within a ‘list item’ tag of an unordered list. The unordered list should have a unique ID, so that you can ‘select’ it later with JavaScript.

    b) Within the ‘list item’ tag, you can have a ‘paragraph’ tag to display your desired message, namely: Current or Available

    c) In the JavaScript (that you add to the footer of the web page), “select” the ‘unordered list’, then iterate through the ‘list items’, check if the date has passed, and set the HTML of the ‘paragraph’ tag appropriately.

  • Hello,
    Yes, there’s probably the following reason to that..

    => You may have WordPress 4.7+ with an hosting where Imagemagick or Imagick AND ghostscript are installed. Else you will not have the new wordpress option that automatically create an image preview of your PDF stored as an attachement image. More info here:
    https://make.wordpress.org/core/2016/11/15/enhanced-pdf-support-4-7/

    If you don’t have this option automatically activated, there’s 2 possibilities to try:
    1) you might maybe find a plugin that add the option to set a featured image to your PDF attachment… then you’ll need to manually attach the image to your PDF each time you download one.

    2) Else, try the following plugin – as WP 4.7 feature – it also require Imagemagick and Ghostscript, but for an unknown reason it was working for me on a website where the default WP 4.7+ behaviour were not working:
    https://fr.wordpress.org/plugins/pdf-image-generator/

    I don’t have more time to investigate, but if someone has the reason why this plugin works where WP 4.7 doesn’t, i’m curious of the answer.

  • Okay, it does indeed work with this plugin! Except for some reason my repeater plugin is saying that it’s not finding any rows. My loop starts like this

    <section class="grid-content">
    <div class="gridGallery">
    <?php
    // check if the repeater field has rows of data
    if( have_rows('card') ):
        // loop through the rows of data
        while ( have_rows('card') ) : the_row();

    And then I have this:

    else :
     ?> <p>no rows found</p> <?php
        // no rows found
    
    endif;

    And it seems that instead of pushing out all my gallery images it’s detecting zero rows and going to the else statement. I’m sure there’s an easy fix here I’m missing but I can’t catch it exactly…

  • If the flex field has the same name as the repeater and all the sub fields of the first layout are exactly the same as the old sub fields then you need to do something like this

    
    // query all of the posts of the post type
    $args = array(/* your query args here */);
    
    $query = new WP_Query($args);
    while ($query->have_posts()) {
      $query->the_post();
      // get the number of rows in the array
      $rows = get_post_meta($post->ID, 'repeater_field_name');
      // create an array containing the first layout $rows times
      $value = array_fill(0, $rows, 'first_layout_name');
      // update with the new value
      update_post_meta($post->ID, 'repeater_field_name', $value);
    }
    
    

    I think this would need to be done after changing the field type but before attempting to update any posts that use the field.

    This can probably also be done with straight db queries, but I’m not sure how to do that.

    As always, when making large changes to the database always back it up first.

  • There’s a filter for that:
    https://www.advancedcustomfields.com/resources/acf-fields-post_object-query/

    Give that a go, and see what comes of it.

  • I found the solution, i post it here if it can help someone :

    <?php if( have_rows('evenement') ): ?>
    	<div class="map">
    	<div class="acf-map">
        	<?php while ( have_rows('evenement') ) : the_row(); ?>
    			<?php $post_object = get_sub_field('lieu_evenement');if( $post_object ): ?>
    				<?php $post = $post_object; setup_postdata( $post ); ?>
    					<?php $location = get_field('geolocalisation'); if( !empty($location) ):?>        
    						<div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>">
                        		<div class="lieu"><?php the_title(); ?></div>
                        	</div>
    					<?php endif; ?>
    				<?php wp_reset_postdata();  ?>
    			<?php endif; ?>
    		<?php endwhile; ?>
    	</div>
        </div>
    <?php else: ?>
    <?php endif; ?>
  • Thank you for your huge answer, I have my last query, My idea is to do on the page post categories with links and I have solved them, now as would be categias with commas and without links.

    Please if you could help me with the okay, this is the last step.

    <ul class="modulejobs">
                <li> <strong>Places:</strong> <?php
    $empresa_terms = get_field( 'empresa' );
    if ( $empresa_terms ) {
      $total = count( $empresa_terms );
      $count = 1;
      foreach ( $empresa_terms as $empresa_term ) {
        echo $empresa_term->name;
        if ( $count < $total ) {
          echo ', ';
        }
        $count++;
      }
    }
    ?></li></ul>
  • Thanks Keith Lock for the excellent after it has worked correctly, Please could you tell me how to delete the places code since in the beginning I already have configured the said word and shows duplicate.

    My Code

    <ul class="modulejobs">
                <li> <strong>Places:</strong> <?php
    $empresa_terms = get_field( 'empresa' );
    if ( $empresa_terms ) {
      $total = count( $empresa_terms );
      $count = 1;
      echo 'Places: ';
      foreach ( $empresa_terms as $empresa_term ) {
        echo '<a href="' . get_term_link( $empresa_term ) . '">';
        echo $empresa_term->name;
        echo '</a>';
        if ( $count < $total ) {
          echo ', ';
        }
        $count++;
      }
    }
    ?></li></ul>
  • Hi @wilfredo123

    The use of get_term_link and passing in the term item should do the trick for you for getting the link.

    You can try the code below… I setup a counter in the test code to be sure not to have a comma at the end of your list. It should display as shown in your image, but please test it for bugs.

    Hope this helps! Let me know.

    
    <?php
    $empresa_terms = get_field( 'empresa' );
    if ( $empresa_terms ) {
      $total = count( $empresa_terms );
      $count = 1;
      echo 'Places: ';
      foreach ( $empresa_terms as $empresa_term ) {
        echo '<a href="' . get_term_link( $empresa_term ) . '">';
        echo $empresa_term->name;
        echo '</a>';
        if ( $count < $total ) {
          echo ', ';
        }
        $count++;
      }
    }
    ?>
    
  • No one? I posted in stackoverflow, maybe is clearer there.

  • I just have a quick follow-up question to this original question, and didn’t want to clutter the forum with additional posts. If I should make an additional post, please let me know.

    So everything is working perfectly fine up until this point. I am able to add and remove Users as I please, so long as the User Field is initially populated in the Post.

    However, when using a Multiple Select User Field, if no User is initially populated in the Post, and the following command is run:

    $test = get_field('cb_roster', false, false);
    print_r($test);

    This returns nothing at all. Therefore, if I use something like:
    array_push($test, $current_user);

    Nothing will happen (since it doesn’t exist).

    So, if I run the following:

    $current_user = get_current_user_id();
    $current_user = strval($current_user); //converting to string just in case
    
    $test = get_field('cb_roster', false, false);
    $current_user = array($current_user);
    print_r($test);
    print_r($current_user);
    
    update_field('cb_roster', $current_user);

    And then run:

    $test = get_field('cb_roster', false, false);
    print_r($test);

    I get a blank value (as though it does not exist).

    The output for print_r($current_user) returns:
    Array ( [0] => 24 )

    Which matches the format of the Array if it were populated from the Post.

    Any input is greatly appreciated!

  • @mattrad-8q962886D4 I’m pretty sure that’s the same snippet I’m using. It does work in the sense that the activation key is activated in the ACF backend, but ACF continues to act like it’s not when I update. I have to deactivate the key and reactivate it manually. It’s happening on all of my and my clients’ sites.

    It was working for a while though. Not sure what changed.

  • FWIW, my answer that’s marked as the solution (even though it’s a workaround) has been fine deploying across multiple environments, including management with ManageWP, since ACF Pro 5 came out. There have been no issues.

    Hey peeps, hereโ€™s a quick fix to add a licence key on theme activation: https://gist.github.com/mattradford/6d5b8f3cd11ce1f62480

    It would be nice to have an official solution though.

  • I’m quite disappointed that this is not solved, yet. I would also be happy to pay an annual fee for that and all the other awesome features of ACF.

  • hi Jakub,

    Maybe try adding ‘type’ => NUMERIC to the query, or remove the quotes from the number?

  • Thanks @keithlock, we are near, but the last step is not working and I cannot figure it out. For testing I have simple query

    
    $args = array(
        'post_type' => 'branch_clinic',
        'meta_key' => 'hospital', // relationship field
        'meta_value' => '536', // ID of hospital
        'meta_compare' => '=',
    );
    

    But it is not working. If I get ID from hospital in regular query, I get right ID – 536

    
    <?php the_field('hospital'); ?>
    

    If I fill with any other fields (branch name) it works. It looks like, that Relationship field cannot be as meta_key… Or do you know, what is going on?

    ———————-

    For explanation, chech this page – http://tuaestetica.pavlovec.net – it is in Czech language, you can switch to English, but it is without data… If you click on “Kliniky” you will see all Hospitals. If you will click on hospital, you will see the detail and all branches at the bottom. In the sidebar, you can specify, which branches you looking for – select location and/or procedure. Here you will see all branches. And there should be those RECOMMENDED branches first and than others.

    ———————-

    Thanks a lot for your helping,
    Jakub

Viewing 25 results - 10,651 through 10,675 (of 21,318 total)