Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • Shortcodes are meant to return data instead of echo it out. Additionally, it looks like the concatenation is malformed after $link1. Any time you’re combining variables with strings you need to use period . to connect them and only a semicolon at the very end. The variables are also not right – you use ‘price1’ in for the field parameter but $go_price is the variable. The anchor needs double quotes to surround the attribute URL. And the conditional needs 2 ampersands.

    All in all it should look something like this:

    function displayprice() {
    
    	$return		= '';
    	$go_price 	= get_field( 'price1' );
    	$go_link 	= get_field( 'link1' );
    
    	if( $go_price && $go_link ) {
    		$return = '<a href="' . esc_url( $go_link ) . '">' . $go_price . '</a>';
    	}
    
    	return $return;
    	
    }
    add_shortcode( 'showprices', 'displayprice' );
  • I don’t know what tutorial you are talking about and your question is too broad.

    Most of ACF works in a plugin the same way it works in a theme.

  • The repeater field holds an integer representing the number of rows. The meta query would look something like this

    
    $meta_query = array(
      'relation' => 'AND',
      array(
        'key' => 'your-repeater-field-name',
        'compare' => 'EXISTS'
      ),
      array(
        'key' => 'your-repeater-field-name',
        'value' => 0,
        'type' => 'NUMERIC'
        'compare' => '>'
      ),
    )
    

    the meta_key exists and it’s value is > 0

  • Thanks John.

    1) Can the snippets on repo be used on ACF5 as well? I ask this since i’ve already upgraded, and it appears the snippets allows for linking of two different field names, as opposed to the plugin which requires the field names to be identical.

    2) On this “acf-reciprocal-relationships-multiple.php”, is the Reciprocal relationship example 1 and Reciprocal relationship example 2 identical?

    https://github.com/Hube2/acf-filters-and-functions/blob/master/acf-reciprocal-relationships-multiple.php

  • I’m not quite sure i understand. When i select page templates i only get the default page template since i didn’t created another. I need to add several extra fields to only a few categories in WC. Could you please clarify which option i need to chose?

  • Yea sure no problem. I have created several categories with woocommerce. And i linked them with ACF like this:
    https://i.imgur.com/k4p1Q7J.png

    However when i go to one of these cats, i don’t see the extra fields, i have saved the post like you said. Also at the bottom of the category page there is nothing, it does show some general fields i added to the woocommerce categories with these settings:
    https://i.imgur.com/oTzI5rm.png

    However these are general fields i need to fill. Those categories are different from the rest and need some additional fields.

    Hope i clarified it enough, otherwise just let me know 🙂

  • Could you clarify?

    So in the acf group, create your fields.

    Then in your rules set “post taxonomy” to equal the taxonomy you want the fields to show for.

    When creating your posts, if you checkbox the taxonomy/category you chose the fields will show.

    To troubleshoot:
    1. check that the fields are showing further down the page, sometimes they will show but they will only appear at the bottom of the post unless you set the priority

    2. Try saving the post to see if the fields show

    Post a screen shot of your rules so we can see 🙂

  • Thank you, this helped me a lot. I know use an if statement in the template to check if it is a gif file and if then use the original image.

    <?php if (exif_imagetype($image['url']) != IMAGETYPE_GIF) { ?>
    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
    <?php } else { ?>
    <img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
    <?php } ?>
  • 'meta_query' => array(
      array(
        'key' => 'hospital',
        'value' => array( 3, 4 ), // array of hospitals IDs from 1st query
        'compare' => 'IN',
      ),

    Cool?

    Not cool 🙂

    This does not work in my particular case. I can query with a single ID and compare “LIKE” but not with an array of IDs and compare “IN”.

  • This is very useful information!

    I would like to know why arrays as value don’t seem to work for this either using “LIKE” or “IN”?

    I have been banging my head against the wall for hours with this…

    If I put a single ID with the compare “LIKE” it works like a charm. But if I put an array in the value, it queries no posts whatsoever…

  • Hi,

    It would have been more simple to help if you posted the code you used to get the User field to populate and to disabled/readonly the sub-field once it is saved.

    To put you on the path (to be confirmed depending on your code) :

    1) Add a specific class to the sub-field in ACF back-end (like “always_disabled”) and add some javascript by using this selector to always disabled the field (see in ACF/WP documentation how to add it properly).

    2) Use the “prepare_field”/”load_value” functions to populate your sub-field value (as you probably done) and to set the field to “readonly” (required to avoid weird reaction of ACF when trying to save a JS disabled input)

    3) Save the sub-field value by using “update_value” / “save_post” or other function (because the disabled and “readonly” sub-field will not be saved automatically).

    It is not necessarily the ultimate solution, but it’s work for me. Hope it helps, send you code if you want more details =).

  • When editing, the ID comes form the url (REQUEST) and the invented ID disappears when the post is saved with its real new id.

    I’d still be glad with a more elegant solution.
    How could I let wp create a new ID itself before the post is saved or even exists?

    here is the complete code of this function:

    add_filter('acf/validate_value/name=fld_pubdoi_doinumber', 'acf_unique_value_field_pubs', 10, 4);
    add_filter('acf/validate_value/name='.$field_name, 'acf_unique_value_field_pubs', 10, 4);
    function acf_unique_value_field_pubs($valid, $value, $field, $input) {
    
        if (!$valid ) {
          return $valid;
        }
       
        if (isset($_POST['post_ID'])) {
            $post_id = intval($_POST['post_ID']);
        } elseif (isset($_POST['post_id'])) {
            $post_id = intval($_POST['post_id']);
        } elseif (isset($_REQUEST['item_id'])) {//IIQINST ONLY
            $post_id = intval($_REQUEST['item_id']);
        } else {
            $post_id = intval('9999999999999999');
        }
    
        //$post_type = get_post_type($post_id);
        $post_type = 'pt_publicacoes_doi';
        $field_name = $field['name'];
    
        $args = array(
          'post_type' => $post_type,
          'post_status' => 'publish, draft',
          'post__not_in' => array($post_id),
          'meta_query' => array(
            array(
              'key' => $field_name,
              'value' => $value
            )
          )
        );
        $query = new WP_Query($args);
     
            if( $query->have_posts() ) {
                $query->the_post();
                $another_post_id = get_the_ID();
            }
    
            if (count($query->posts)){
              return $field['label'].' already exists';
            }
    
            return true;
    
    }

    And the form args:

    
    $item_id = ( isset($_GET['item_id']) ) ? $_GET['item_id'] : 'new_post';
    
    acf_form(array(
            'id' => 'iiq-addedit-pub-form',
            'post_id'       => $item_id,
            'post_title'    => false,
            'post_content'  => false,
            'form_attributes' => array(),
            'submit_value' => __('SAVE', 'acf'),
            'html_submit_button'    => '<input type="submit" class="but-form" value="%s" />',
            'new_post'      => array(
                'post_type'     => 'pt_publicacoes_doi',
                'post_status'   => "publish"
            ),
            'updated_message' => __($text_return, 'acf'),
            'html_updated_message'  => '<div id="adm-message" class="updated"><p>%s</p></div>',
            'return' => $return_url,
          
        ));
  • As the writer of the original code, I’ve never tried it on a front end post.

    If the form is editing and existing post then a post ID should be set and the code should work.

    However, if this is for creating a new post, as @howdy_mcgee says, you’ll have issues.
    1) You can’t check for it

    2) Using a made up post ID will not work since the code requires the post_type and with a made up ID or an id of ‘new_?’ get_post_type() will return false.

    In the case of #2,
    1) you need to forget about checking to see if the post id is set and just remove that code.
    2) You need to hard code the post type(s) to check and not rely on get_post_type()
    3) You need to remove the 'post__not_in' => array($post_id), portion of the query since being a new post you don’t need to worry about the current post returning a false positive.

  • Hopefully you’re not trying to update based off the invented post ID – If you can you should let WordPress create IDs for new posts ( which it does in MySQL ) otherwise you’ll surely run into issues down the road.

    Difficult to suggest the best course of action without the context of the rest of the code block.

  • Hi Howdy_McGee, thanks a lot for your reply.
    At some point I figured it out that the problem was the missing id for new post.
    So I did the following:
    (probably not the best idea, but…)

       (...)
       if (isset($_POST['post_ID'])) { 
            //just like it was at first
            $post_id = intval($_POST['post_ID']);
    
        } elseif (isset($_POST['post_id'])) { 
            //just like it was at first
            $post_id = intval($_POST['post_id']);
    
        } elseif (isset($_REQUEST['item_id'])) {
            // BECAUSE MY FORM COULD BE EDITING INSTEAD OF INCLUDING
            $post_id = intval($_REQUEST['item_id']);
    
        } else { 
            // I INVENTED AN ID FOR THIS NEW POST
            $post_id = intval('9999999999999999');
        }
    
        //And since I couldnt check the post-type for a new post, 
        //I specified the post-type here (cause in my case this function only applies to this form)
        $post_type = 'pt_publicacoes_doi';
    
        $field_name = $field['name'];
    
    (...)
  • ACF does not automatically update relationships on the other end, that is what https://www.advancedcustomfields.com/resources/bidirectional-relationships/ addresses. Alternately you can use this plugin https://wordpress.org/plugins/post-2-post-for-acf/.

    By using the above code or the plugin you remove the need to do a reverse relationship query as described in the first document https://www.advancedcustomfields.com/resources/querying-relationship-fields/

  • the repeater add on is not required if you are using ACF Pro, remove the add on.

  • I copy and pasted the code supplied in your Stack Overflow question, changed the single quotes to double quotes, changed the ‘to’ email, and saved the code as a custom 1 file plugin. It worked as expected, I received the user field in the email sent.

    If you’re not getting it in your email then there’s something not provided that we’re missing or the data isn’t saved into the usermeta table.

  • I’m also receiving a Bad Request error trying to update from 5.7.4 to 5.7.5 (multisite):

    
    Plugin Advanced Custom Fields PRO bijwerken (1/1)
    
    Update downloaden van https://connect.advancedcustomfields.com/v2/plugins/download?token=eyJwIjoicHJvIiwiayI6ImIzSmtaWEpmYVdROU5USXpOako4ZEhsd1pUMWtaWFpsYkc5d1pYSjhaR0YwWlQweU1ERTFMVEF6TFRFNUlERTFPakkyT2pBMCIsIndwX3VybCI6Imh0dHBzOlwvXC9ieWxpZW4uY29uc3VsdGluZyJ9…
    
    Er is een fout opgetreden bij het bijwerken van Advanced Custom Fields PRO: Download mislukt. Bad Request.
  • Sorry, I found myself what was silly :-S It’s often while asking something that you found the solution, which is obvioulsly :

    <?php if( get_field('status') == 'no'): ?>
    													<div class="side-button">
    														<a href="<?php the_field('the_link', get_the_ID()) ?>" target="_blank">Click the link</a>
    													</div>
    												<?php elseif	( get_field('status') == 'yes' ): ?>
    													<div class="side-button-dark">
    														Special message
    													</div>
    												<?php endif; ?>

    Sorry, but I don’t find where to delete thread…

  • Haha … yes definitely have a custom <form> with a method="post" !
    It was working fine before I added the acf_form() and the acf_form_head()!
    I was expecting to have to save the ‘acf’ data as you described above.

    I’ll cobble together a concise full example and post here if I’m still running into issues.
    Thanks again

  • This may be a silly question but are you sure your <form> tag has method="post" set? I was under the assumption you have a custom <form> wrapper to include you custom inputs along with an acf_form() with a field group of inputs. It may be easier to replicate and debug given the full form code.

    If you figure out the issue though be sure to come back and let us know!

  • Thanks again for your help.

    I placed the code above into my functions.php file, but the event doesn’t seem to be firing. Neither am I getting anything coming through in the $_POST(‘acf’)

    Turns out it is only saving my acf fields data, and is no longer saving my other meta data now. When I click the ‘Submit’ button, it now seems to coming back as a GET request method????? Maybe the acf_form_head() is redirecting again once it has save the ACF fields it knows about, so it’s never getting to my POST processing code?

    I need to do some more testing I think… will post an update once I have figured out whats going on.

  • I think the problem is your use of single quotes where there should be double quotes:

    get_field( 'user_phone', 'user_{$user_id}' )

    Should be

    get_field( 'user_phone', "user_{$user_id}" )

    I’ve left an answer on your post.

  • It’a more or a general PHP/WP question.

    It looks like you are setting every “tab” to active. Basically, if you have you posts ordered so that they are all in the future then the first one will always be the soonest event. You already have a counter so I think this should work
    <?php if ($counter == 0) { echo 'active'; }

Viewing 25 results - 9,226 through 9,250 (of 21,340 total)