Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • Automatic cleanup will be difficult no matter what information is stored.

    When would the cleanup happen?
    Each of the following conditions would leave behind orphaned data and would have its own problems and hurdles to jump. Some of them are more complicated to achieve than others.

    • When a field is deleted
    • When a field group is deleted
    • When the location of a field group is changed
    • When a field is hidden by conditional logic
    • When the sub fields of a repeater/flex field/clone change
    • When a field is moved from one field group to another – should data be deleted or moved?
    • When the parent of a field is changed (When a field is dragged into a different location, for example one repeater to another) – should data be deleted or moved?
    • When the field name is changed – should data be deleted or moved?
    • I’m sure I’m missing others

    What data do you think ACF could store to help make the clean up of data in each of the above conditions easier?

    How could ACF overcome the limits of WP when it comes to the issue of performing all of the checking and deletion of data from the five locations where it can be stored (_postmeta, _termmeta, _usermeta’, _commentmeta and options) when each check/deletion will require calling a WP function to delete the specific data? If the answer to some of the conditions is that data would be move then this will also require calling the WP function to insert the data in the new location. How can this be performed on a large site on every post without causing the admin to time out due to the number of db queries that must be performed?

  • Hi
    this is the code that i used:
    (function($) {
    $(‘#firstdate .acf-date-picker input.hasDatepicker’).live(“change”, function(e) {
    var getval = $(this).val();
    var dataname = $(“#firstdate”).attr(“data-name”);
    if (dataname == “fecha_de_llegada”) {
    var makedate = $(this).val().split(“/”);
    var date = new Date(makedate[1] + “/” + makedate[0] + “/” + makedate[2]);
    date.setDate(date.getDate() + 1);
    if (!isNaN(date.getTime())) {
    var getnew = date.toLocaleDateString(‘en-GB’);
    var getmyd = getnew.split(‘/’);
    var gyear = getmyd[2].toString();
    var gmonth = getmyd[1].toString();
    var gday = getmyd[0].toString();
    $(“#seconddate”).find(‘input[type=text]’).val(date.toLocaleDateString(‘en-GB’));
    $(“#seconddate”).find(‘input[type=hidden]’).val(gyear+gmonth+gday);
    } else {
    alert(“Invalid Date”);
    }
    }
    });
    })(jQuery);

    make sure that you change the ID/classes of you element:
    #firstdate, #seconddate

    hope it helps

  • Hi Guys –

    John thanks or helping Byrant out with his issue – I have a similar question but I can’t quite make the leap from the above example to mine. Essentially what I need to do is display custom text below a given sub field (it’s a page_link field) that get’s the ID of the selected page_link field, and displays it.

    I’ve been able to render text below the select field fine, but when I echo the field value, it’s just echoing the ID for the current page, not the page_link field.

    Any help would be greatly appreciated.

  • I have been looking into a way to do this.

    Before I get into how this can be done, with some problems, I just want to point out that doing this the way that most people would expect it to be done is nearly impossible. If you know anything about the way ACF and WP work, and you’ve looked into this you’ll quickly come to the same conclusion.

    Sometimes “impossible” just means very difficult, but in this case it really does mean impossible. WP has limits to what it can do and attempting to have ACF clean up all unused values when they are no longer needed would run into these limits imposed by the way that WP is built. In almost all cases it would simply cause the saving and updating to time out and not complete.

    I would love to hear from people that use other custom field plugins an know if any of them clean up after themselves the way people want ACF to clean up after itself. I’d look myself, but I have no interest in these other plugins or seeing what happens with unused data.

    I’ve actually started trying to explain why it is impossible several times and failed. Trying to think about what needs to be done to have this automatically happen under every condition nearly makes my head explode.

    There is only one way I can think of that this can be done, and even it cannot be made to work under all conditions. That way is to delete all existing data before ACF updates the fields, or to just wholesale delete all content whenever an ACF field is deleted.

    The condition where this will not work is altering the location rules of a field group. If a field group is located on posts and you change the location to pages, there simply isn’t any easy way to then remove all of the field values from all of the posts that were already saved. Not without checking every object in WP to discover what objects the fields should not be saved for.

    There is also a condition that will cause data that you don’t want deleted to be deleted anyway. This condition will happen with cloned fields and in any other place where a field key is duplicated.

    There is also the case of someone deleting fields when the goal is to keep the field data because you want to move the fields into PHP and remove the field group from the ACF admin.

    I’ve actually started building a plugin that will do this, but I hesitate do complete it and make it publicly available because there are cases were, if used improperly, people will end up having content deleted that they do not want deleted and hold me responsible for messing up their site. While I know it will work if used properly, I’m afraid that there are probably too ways that it could be used improperly.

  • Ah! so the question wasn‘t as stupid as I thought 😀

    Thanks!

  • OK, I managed to solve it by myself… the main problem was, that I used the name of the custom post type instead of the name of the ACF-relationship-field.

    	$methods = get_posts(array(
    		'post_type' => 'page',
    		'meta_query' => array(
    			array(
    			'key' => 'persons', // name of custom field
    			'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
    			'compare' => 'LIKE'
    			)
    		)
    	));
    
  • Thanks https://support.advancedcustomfields.com/forums/users/hube2/
    This worked but was still not entirely the solution as I found I had yet another custom field to check against..and applying the way you solved this I thought I had it…

    What I need is something like this but it isn’t working..

    Pseudo code

    IF all are relation are true (AND)
    AND
    sale price <300
    AND
    either status NOT EXISTS
    OR
    either status =”
    AND
    either sp-alt NOT EXISTS
    OR
    either sp-alt =”

    code..` ‘meta_query’ => array(
    ‘relation’ => ‘AND’,
    //AND
    array(
    ‘key’ => ‘sale_price’,
    ‘value’ => 300000,
    ‘type’ => ‘NUMERIC’,
    ‘compare’ => ‘<‘
    ),
    //AND
    array(
    ‘relation’ => ‘OR’,
    array(
    ‘key’ => ‘status’,
    ‘compare’ => ‘NOT EXISTS’
    ),
    array(
    ‘key’ => ‘status’,
    ‘value’ => ”,
    ‘compare’ => ‘=’
    )
    ),
    //AND
    array(
    ‘relation’ => ‘OR’,
    array(
    ‘key’ => ‘sp-alt’,
    ‘compare’ => ‘NOT EXISTS’
    ),
    array(
    ‘key’ => ‘sp-alt’,
    ‘value’ => ”,
    ‘compare’ => ‘=’
    )
    ),`

    I get that we need to check OR for each field as it can be one or the other or at least one if it is both..

    I only want to see an item if it is less than 300 and doesn’t have a value in any of the fields sp-alt or status..if anything is in either of those fields I DON’T want to show the item. My logic seems right after you helped me get this far.

    TY anyway I am going to play more..

  • Hi,

    after a long time, I found what I think be a solution

    in core/validation.php line 158 change:

    if( !acf_verify_ajax() ) die();

    to

    if( acf_verify_ajax() ) die();

    this solve my question, but updates concern me

  • Oh, interesting approach regarding the closing out of php. I like it. Kind of like formal writing avoids contractions. Probably a good approach for me too since I’m just learning the intricacies of php but am fine with most html.

    Name instead of label… So that’s how taxonomy’s handle things differently then? I was using a snippit for handling custom fields. I tried using a snippit my own theme uses as well…
    <?php echo get_the_term_list( $post->ID, 'portfolio_skills', '', '<br />', '' ); ?>
    (this time closing the tags rather than mess with all the single quotes…especially since I’m not worried about spaces and line breaks right now)

    However, since ‘portfolio_skills’ (I used ‘media’ instead) is my theme’s own custom field and probably not a taxonomy per se (albeit the values are user generated), maybe $terms->ID would be better $terms->NAME or will I break the theme again?

    Maybe a better question is to ask what would be a good resource for learning and practicing php? I’m like the person learning a new language asking for a “tall refreshing glass of water”. I know that I’ll get a glass of water without understanding that “refreshing” is superfluous and “tall” is too specific for my needs.

    Thanks again for all your efforts. I know it’s a labor of love teaching without pay.

  • You have to create a loop that goes over the value and dynamically generate the meta query. For example, assuming that your $_POST value is an array;

    
    $meta_query = array('relation' => 'OR');
    foreach ($_POST['year'] as $year) {
      $meta_query[] = array(
        'key' => 'year',
        'value' => '".$year."',
        'compare' => 'LIKE'
      )
    } // end foreach
    $args = array(
      'posts_per_page' => -1,
      'meta_query' => $meta_query
    );
    
  • As far as I know ACF has always used the field keys for these values. No you cannot change these except for changing the field keys (field keys must start with “field_”). Yes, these stay the same, these are the field keys which uniquely identify each field.

  • on this page https://www.advancedcustomfields.com/resources/query-posts-custom-fields/ see 3. Multiple custom field values (array based values)

    but the value given in the examples in incorrect. You also need to include quotes around the value to find exact matches.

    
    'value' => '"Melborne"',
    'compare' => 'LIKE'
    
  • Hi @James

    it looks like you solved this issue above and I was wondering if you could assist with mine its along the same lines when you have a chance.

    I have created a custom field with map loaction this is attached to a category in of posts.
    Ideally what i want to happen is elements of the post display on the map inside the pointer window when clicked.

    Im building out a wordpress site that plots custom data on a google map using Advanced Custom Fields Pro but can’t get it to generate the map using the custom page I have created.

    I have created a Google Map Picker with ACF which I have assigned to a post category type ID 4. This is functioning as expected and I can pick the location for each post

    In my custom template for wordpress site I have entered the below code to call any location information from the Category in question in this case its ID is 4

    This Section pulls and displays the location as expected on the page ( I will be hiding it in the final build)

    <?php
    $catquery = new WP_Query( 'cat=4&posts_per_page=10' );
    while($catquery->have_posts()) : $catquery->the_post();
    ?>
    
      <?php the_field('location'); ?>
    
    <?php endwhile; ?>
     </div>

    However the map just pulls the first blog and does not display the other Below is the code im using to call the location and pass it into the map

    <?php if( have_rows('sdg_location') ): ?>
        <div class="acf-map">
            <?php while ( have_rows('sdg_location') ) : the_row(); 
    
                $location = get_field('location');
    
                ?>
                <div class="marker" data-lat="<?php echo $location['lat']; ?>" 
        data-lng="<?php echo $location['lng']; ?>">
    
                </div>
        <?php endwhile; ?>
        </div>
    <?php endif; ?>

    Can you advise of a better method of doing this? Is there a way to pass the location from the categories directly into the map call?

    Thanks a million for your help in advance

  • Thanks, John.

    Sorry…I’m a bit cloudy about understanding exactly what ACF Pro does. I was confusing the flexible content field with something that would allow me to add a link to each choice, but further reading is leading me down a rabbit hole, so maybe it’s not the answer.

    Yes, that code works for links. So would I also use something like

    <a href="<?php echo get_term_link($term); ?> . echo $field['label'] . </a>

    to show the link as the name of the category? It’s not working so something isn’t right in my syntax. I’m a little confused as to when to use single quotes to indicate switching to html or single out items not native to php, and when to use the dots. Thanks again. You’ve helped tremendously already.

  • ACF does not automatically add field/content to the front end or your site. This requires altering the code of the template of your theme and/or WC to show the values of the fields. https://www.advancedcustomfields.com/resources/#functions

  • Replying to the any help and @sib’s response to that. This a a forum where you’re getting help from other users and not the developers of the plugin. There are some users like myself that spend a lot of time here attempting to help others with their problems. I do try to look at every question and it really doesn’t matter if you’re using the free version of the premium version.

    As far as your question goes. Honestly, I can’t really tell what I’m looking at or what the problem is or even what to ask in order to get more information. The problem is just not really explained clearly enough.

    Maybe answering some of these question will let someone help you.

    What are the location rules of your field group? What type of field are you having the issue with? What do you expect to happen? What is happening?

  • I’ve read all of your comments, but I may not understand what you’re looking for.

    I’m really not sure what you mean by “the linking option” in the pro version.

    You are using a taxonomy field and you want to output links to the terms that have been selected?

    If this is true then how you would code this depends on what you have the Return Value of the field set to. You would most likely be better off returning a term object.

    
    $terms = get_field('media');
    if ($terms) {
      foreach ($terms as $term) {
        ?>
          <a href="<?php echo get_term_link($term); ?>"><?php echo $term->name; ?></a>
        <?php 
      }  // end foreach
    } // end if
    
  • I’m not exactly sure what it is you’re trying to do really.

    You’re looking for posts that do not have any value set for “status” and a value in “sale_price” that is < 300000?

    If this is correct then:

    
    'meta_query' => array(
      'relation' => 'AND',
      array(
        'key' => 'sale_price',
        'value' => 300000,
        'type' => 'NUMERIC',
        'compare' => '<'
      ),
      array(
        'relation' => 'OR',
        array(
          'key' => 'status',
          'compare' => 'NOT EXISTS'
        ),
        array(
          'key' => 'status',
          'value' => '',
          'compare' => '='
        )
      )
    )
    
  • You need to check that the value “EXISTS” or “NOT EXISTS” for meta values that have never been set as well has empty string “” values for those that have been set but do not have a value. https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

  • To clarify now that I understand more:

    I am using my theme’s existing custom taxonomy portfolio-category, but I don’t know how to perform a var_dump of that field (assuming it’s a field and not a subfield) outside of the loop. I want to eventually be able to use each category I assign via checkbox a link, and to use my portfolio’s existing archive view to view the posts under that category.

    In my theme:
    I have one category in my theme’s ‘portfolio-category’ named ‘media’ (slug is also media) and five children assigned under that category:
    Acrylic (slug: acrylic-media)
    Textured Acrylic (slug: textured-acrylic-media)
    Digital (slug: digital-media)
    Prismacolor (slug: prismacolor)

    In ACF
    Field label: Media
    field name (slug?): media
    field type: Taxonomy
    Taxonomy: portfolio_category
    Field Type: Checkbox
    Term is ID, not object.
    Null is currently not allowed

    Since I’m using a taxonomy, using anything like [‘label’] would be out of the question (right?), which is why any of the sub-field snippits I tried did not work, and that a value of 5 from the var_dump was because there is 1 field and 4 sub-fields in my theme’s taxonomy assigned the field ‘media’. So if this method is too complex, then I could resort to another option and attempt to create my own archive function in the (probably distant) future…

    If checkbox were chosen instead of taxonomy, I could assign each category a label and a variable in the choices fields in ACF

    So something like

    acrylic: https://www.mysite.com/acrylic
    prismacolor: https://www.mysite.com/prismacolor
    etc.

    would work if I wanted to set a value to an ‘href’. But…

    I would have to call each subfield by name to retrieve the values from that field, right? Or would there be any way to assign a x-variable type value so I can just add what I wanted to ACF as I add more subfields? A pain, but not quite as much writing code for every subfield in addition to adding to ACF and therefore having two areas to edit.

  • Hi John – Perhaps this will help us. I really appreciate anything you can do to help.

    I’m using relavennsi and found this discussion where ACF support assisted people in getting something very similar to work. Does this info help at all?

    https://www.relevanssi.com/knowledge-base/add-custom-fields-search-excerpts/

    Using the filter supplied by Relavenssi, I entered my custom field names, but the images don’t display:

    add_filter(‘relevanssi_excerpt_content’, ‘custom_fields_to_excerpts’, 10, 3);
    function custom_fields_to_excerpts($content, $post, $query) {
    $custom_field = get_post_meta($post->ID, ‘add_image_search_results‘, true);
    $content .= ” ” . $custom_field;
    $custom_field = get_post_meta($post->ID, ‘wh1‘, true);
    $content .= ” ” . $custom_field;
    return $content;
    }

  • I got it working. As what I had above was showing the taxonomy term IDs I found how to turn these IDs into text terms that could be used within $the_query $terms array. I’m not sure if this is the best way to solve the problem so if you know any way to streamline this code, I’d greatly appreciate knowing how.

    global $post;
    $row1 = get_field('homepage_sidebar_sponsor_logos' );
    $first_row = $row1[0];
    $first_row_id = $first_row['contestant_year_category' ];
    $first_row_term = get_term_by('id', absint( $first_row_id ), 'year_type');
    $first_row_name = $first_row_term->name;
    
    $row2 = get_field('homepage_sidebar_sponsor_logos' );
    $second_row = $row2[1];
    $second_row_id = $second_row['contestant_year_category' ];
    $second_row_term = get_term_by('id', absint( $second_row_id ), 'year_type');
    $second_row_name = $second_row_term->name;
    
    $row3 = get_field('homepage_sidebar_sponsor_logos' );
    $third_row = $row3[2];
    $third_row_id = $third_row['contestant_year_category' ];
    $third_row_term = get_term_by('id', absint( $third_row_id ), 'year_type');
    $third_row_name = $third_row_term->name;
    
    $the_query = new WP_Query( array(
        'post_type' => 'contestants',
        'tax_query' => array(
        array(
          'taxonomy' => 'year_type',
          'field' => 'slug',
          'terms' => array( $first_row_name, $second_row_name, $third_row_name )
        )
      ))
    ) ;
  • What is the return value for the field set to? If it is URL then

    
    <div style="background-image: url(<?php the_field('image_field_name'); ?>);">
    
  • The AJAX fields can field to load if there is a JavaScript error or there is a PHP error during the AJAX request. You need to look for JavaScript errors and turn on debugging and logging and check the error log to see if there are any php errors during the request. https://codex.wordpress.org/WP_DEBUG. If both of these are negative then I’d go back to the internet connectivity assumption, especially if the site works fine for me and only breaks for the client.

  • You can get the entire repeater, including nested repeaters

    
    get_field('repeater_name');
    

    or you can get an entire nested repeater

    
    get_sub_field('nested_repeater_name');
    

    this will return the entire contents of the repeater as an array and then you can jump back and forth in the array as you need to.

    But finding a specific value in the repeater will require looping through the array or nested array to find the row you’re looking for in any case.

Viewing 25 results - 11,051 through 11,075 (of 21,318 total)