Support

Account

Forum Replies Created

  • Hello…

    Good question…. here’s how I might tackle it…

    First… as we know…

    We have a ‘Doctors’ CPT
    … with a ‘Locations’ Relationship field.

    This ‘Locations’ field may have a series of Location IDs (say: 5, 6, 7)

    Now, we have the ‘Locations’ CPT

    When looking at ‘Edit Locations’
    … we could have a ‘Doctors’ Relationship field here.
    In it… we could work this hook
    … to fetch all the Docs that are attached to that Location.

    Now, as an alternative… if you just wanted to do this for ‘Display’ purposes, you can pre-populate another field with the doc data… just use some other field type other than Relationship… like the ‘Enhanced Message’ add-on that allows for PHP, or maybe some other built-in field type like textarea, and make it read-only. Example here for making it read-only.

    But… it’s better probably to use a Relationship field to make for smarter editing. But we have to keep the data in synch on our own from the way I understand it. So… each time a change is made to the ‘Doctors’ Relationship field when editing ‘Locations’, you can write logic that loops through and updates the ‘Doctors’ records (i.e. adds a location or removes a location).

    Now, I haven’t thought far enough ahead to point you how to do the last part, because I’m not sure you wanted to get this far down the rabbit hole 🙂 Let me know!

  • @redeclipse

    get_page has been deprecated… it is recommended to use get_post() in favour of it.

    With that said… would a custom WP_Query be a better choice in this scenario?

    If you agree… check out an example below of the arguments that you could pass to the WP_Query when using a True/False ACF field.

    Hopefully you can pick apart and make sense of it for your use case:

    $projects_args = array(
      'post_type' => 'projects',
      'post_status' => 'publish',
      'relation' => 'AND',
      'meta_query' => array(
        array(
          'key' => 'cc_project_complete',
          'value' => FALSE,
          'compare' => '='
        ),
        array(
          'key' => 'cc_project_customer',
          'value' => $customer_id,
          'compare' => '='
        )
      ),
      'fields' => 'id, title, cc_project_job_num, cc_project_load_ship_date, cc_project_asap, cc_project_po_received_date, cc_project_dept_planned_1, cc_project_dept_planned_2, cc_project_dept_planned_3, cc_project_dept_planned_4, cc_project_dept_planned_5, cc_project_dept_planned_6, cc_project_dept_planned_7, cc_project_dept_planned_8, cc_project_dept_planned_9, cc_project_dept_planned_10, cc_project_dept_planned_11, cc_project_dept_planned_12, cc_project_dept_planned_13, cc_project_dept_planned_14, cc_project_dept_planned_15, cc_project_urgency, cc_project_asap_lead_time, cc_project_rush_lead_time, cc_project_standard_lead_time, cc_project_complete, cc_project_customer'
    );
    

    ‘cc_project_complete’ is my True/False ACF field. Also… you can decide what fields to return using ‘fields’. And in this example… I made sure that 2 criteria were satisfied by using ‘relation’ => ‘AND’ with my ‘meta_query’

    Hope that steers you in the right direction.

  • Hi @kubajjz

    Below are the arguments for a WP_Query I created recently that hopefully you can pick apart and make sense of for your use case:

    $projects_args = array(
      'post_type' => 'projects',
      'post_status' => 'publish',
      'relation' => 'AND',
      'meta_query' => array(
        array(
          'key' => 'cc_project_complete',
          'value' => FALSE,
          'compare' => '='
        ),
        array(
          'key' => 'cc_project_customer',
          'value' => $customer_id,
          'compare' => '='
        )
      ),
      'fields' => 'id, title, cc_project_job_num, cc_project_load_ship_date, cc_project_asap, cc_project_po_received_date, cc_project_dept_planned_1, cc_project_dept_planned_2, cc_project_dept_planned_3, cc_project_dept_planned_4, cc_project_dept_planned_5, cc_project_dept_planned_6, cc_project_dept_planned_7, cc_project_dept_planned_8, cc_project_dept_planned_9, cc_project_dept_planned_10, cc_project_dept_planned_11, cc_project_dept_planned_12, cc_project_dept_planned_13, cc_project_dept_planned_14, cc_project_dept_planned_15, cc_project_urgency, cc_project_asap_lead_time, cc_project_rush_lead_time, cc_project_standard_lead_time, cc_project_complete, cc_project_customer'
    );
    

    ‘cc_project_complete’ is my True/False ACF field. Also… you can decide what fields to return using ‘fields’. And in this example… I made sure that 2 criteria were satisfied by using ‘relation’ => ‘AND’ with my ‘meta_query’

    Hope that steers you in the right direction.

  • Hi @bravenewmedia

    Not sure what you mean.

    When using the Link field with a Return Value of ‘Link Array’ you can get ‘title’ like so:

    <?php
    $link = get_field('link');
    echo $link['title'];
    
    // Button Example
    ?>
    <a class="button" href="<?php echo $link['url']; ?>" target="<?php echo $link['target']; ?>"><?php echo $link['title']; ?></a>
    

    It is the ‘Link Text’ in the dialogue box when adding the link. Know what I mean?

  • Hi Greg…

    Just checking the relevance of your Post ID in the example above… I see that you are using a different Post ID ( 5994 vs 5873 ) – was that just an oversight, or irrelevant because you are just showing an example?

  • Hi @designlobby

    Groups just have one row.. but you can use a Repeater of Groups.

    I did this for a test:

    Repeater: highlights
    —> Group: highlight
    ——> Text: title
    ——> Text: desc
    ——> Link: link
    ——> Image: image

    Code example:

    <?php
    if ( have_rows('highlights') ) {
      while ( have_rows('highlights') ) { // Repeater Loop
        the_row();
        if ( have_rows('highlight') ) {
          while ( have_rows('highlights') ) { // Group Loop
            the_row();
            $title = get_sub_field('title');
            $desc = get_sub_field('desc');
            $link = get_sub_field('link');
            $image = get_sub_field('image');
            echo '<h2>' . $title . '</h2>';
    ?>
    <a href="<?php echo $link['url']; ?>"><img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /></a>
    <p><?php echo $desc; ?></p>
    <?php
          }
        }
      }
    }
    ?>
  • Hi there @krtmedia

    Initially you will want to create the Options Page. You can use this code resource, or this plugin.

    Here’s example code for an Options Page that can be added to functions.php or a custom plugin:

    <?php
    if( function_exists('acf_add_options_page') ) {
     
    	$option_page = acf_add_options_page(array(
    		'page_title' 	=> 'Global Settings',
    		'menu_title' 	=> 'Global Settings',
    		'menu_slug' 	=> 'my-global-settings',
    		'capability' 	=> 'edit_posts',
    		'redirect' 	=> false
    	));
     
    }
    ?>

    Then, you create a Fieldset within ACF for that Options page.

    So… you create a URL field called “pricelist” for example.

    Then… you visit the Options Page and give your “pricelist” field a value, and click “Update”.

    Then… to reference it with code..

    <?php
    // to 'echo' it
    the_field('pricelist', 'option');
    
    // to return the value, and perhaps assign it to a variable for later use
    $price_list = get_field('pricelist', 'option');
    ?>

    Is that helpful, or do you need further assistance?

  • Hi @russellknight1979

    What did you choose for the ‘Return value’ for the Images?

    It is dependent on the Return Type how you display the data..

    Have a peek here, and let me know if I could help further.

  • @shonlevi

    Hmmm… this could be tricky.

    First… have a peek through this thread here.

    You will see that.. in order to pre-populate a repeater, the rows will have to exist ahead of time.

    What if…

    1) You had a ‘codename’ text field.
    2) You had a ‘howmany’ number field (to decide how many codes to generate).
    3) You had a textarea field to store your coupons…
    … you could store them one per line (and just ‘append’ them when you add more), and then separate the data with a “pipe” | symbol to deal with later. You can use the PHP explode() function to split the data by the “pipe” symbol.

    Example:

    Codename: EXAMPLE
    Howmany: 3
    Generated Coupons:

    Name1|Description1|Example122
    Name2|Description2|Example123
    Name3|Description4|Example999

    Here’s a page that describes how to extract each line from a textarea field. Then, of course, use ‘explode’ to separate the data from each line.

    Hope that helps. There may be a better way, it’s just not coming to me if so 🙂

  • You can place the code in your theme’s functions.php file or in a custom plugin. This link explains the differences. I like to use custom plugins, that way, if switching themes, my customizations remain. Using the Pluginception plugin (not necessarily supported by ACF, just a tool I like to suggest to simplify things) allows you to quickly create a plugin for this purpose.

    I can’t fully understand your exact use case. Please explain it step by step with full details 😉 This thread might get you going otherwise.

  • Hi @abbasinho

    One way to accomplish that is to use the WP function get_queried_object_id

    With that you can grab the Post/Page ID of the current page before you start iterating through your loop.

    Then, in your loop you can match $nav_item->ID with the returned value of get_queried_object_id then you can apply the class appropriately.

    In my testing, I set a variable containing the class name at the top of the loop if there was a match, then reset the variable at the end of the loop. There are a bunch of different ways, but using get_queried_object_id is key.

    I realize this is a late reply, but hopefully it’s helpful to you or someone else.

    Here’s my test code:

    <?php
    $current_page_id = get_queried_object_id();
    $class = '';
    $posts = get_field('relationship', 23);
    if( $posts ) {
      $content .= '<ul>';
      foreach( $posts as $p ) {
        if ( $current_page_id == $p->ID ) {
          $class = ' style="text-decoration:line-through"';
        }
        $content .= '<li>';
        $content .= '<a href="' . get_permalink( $p->ID ) .'"' . $class . '>' . get_the_title( $p->ID ) . '</a>';
        $content .= '</li>';
        $class = '';
      }
      $content .= '</ul>';
    }
    echo $content;
    ?>
  • Hello @shonlevi ,

    If I understand correctly, perhaps you could have 3 fields…

    Field 1: Text box for value such as: EXAMPLE

    Field 2: Number… for how many coupons to generate

    Field 3: Repeater field for the coupon codes.

    Then, you could enter values in the first 2 boxes, and then use the update_field function to generate the codes..

    Here’s partial example code for updating a repeater:

    <?php
    $prefix = get_field('prefix', $post_id);
    $number_of_coupons = get_field('number_of_coupons', $post_id);
    $repeater_field_key = "field_12345678";
    $i = 1;
    while ($i <= $number_of_coupons) {
     //// use PHP 'rand' or 'shuffle' to generate some random numbers
     //// create a 'value' by joining the 'prefix' with a 'random number'
     //// put your logic in here to add values to the array
      $i++;
    }
    
    ///// here is how to add one value to the array
    $value = array(
      array(
        "coupon_code" => "Foo"
      )
    );
    update_field( $field_key, $value, $post_id );
    ?>

    Hope that gets you on the right path… clearly there is some work left to do and some testing, but that should get you going!

  • HI @verena

    Thanks very much for your detailed question and providing the version numbers. I appreciate that. The good news is, I was able to duplicate this issue quite easily. However, I am not sure where to begin though to sort out the issue. It is certainly something to bring up to the developers.

    I will let the ACF developer know, can you reach out to WPGlobulus?

    I will update this thread when I hear back. I can’t guarantee a response time and what sort of priority will be assigned to it. With that said, I will try and see if I can sort anything out on my own time to help move things along.

    Talk soon!

    EDIT: Ticket submitted to ACF support about the incompatibility

    EDIT: ACF Support has been in touch with WPGlobus about this… hopefully it is rectified soon

  • Thanks @gavin310 I will let the web folks know. Appreciate that.

  • @csk87

    Well… my theory was incorrect. Because… with ACF Pro… when switching to Swedish, I was still able to see “Link” – it just wasn’t translated.

    With ACF versions prior to 5.6.0, the “Link” field type doesn’t exist. I apologize for pointing you down the wrong path.

    I have never actually used the Link Field until just now in my testing, but I could see how it would be handy.

    There are 2 return types for the Link field… an Array (giving you URL, Title, and Target), and simply a URL.

    While not ideal… you could use a Text field if just going after the URL.

    If wanting all of the data, you could have 3 fields. 2 text fields and a checkbox.

    Hope that helps. Let me know if I could be of further help.

    EDIT: I just Googled it, and there are Link/URL field add-ons for ACF in the WordPress plugin repository. I can’t account for any of them though, because I never used them. Best of luck with your project!

  • @jketelaar

    OK, well.. now that we found the incompatibility… what to do?

    For sure… don’t stop using the tool if it’s needed.

    We certainly should let both developer’s know of the incompatibility. I will do that with the ACF developer, and perhaps you could reach out to the developer of The Events Calendar plugin.

    As for a workaround… I will edit this post later with what I discover. I’m not sure the depth of it, but if it’s a quick thing… I will offer a workaround. Talk soon!

    EDIT:

    I wasn’t able to duplicate the issue. See attached. I have ACF Pro installed, and the free version of The Events plugin. Is that the same setup you have? And… when you deactivated the Events plugin, all was good?

  • Hi Pietro,

    Yes… sorry to have thrown so many suggestions to you in my reply. I was just elaborating that there are plenty of choices.

    I took another look at your site… and see where you have the code.

    A simple approach would be to create a second field for the URL. This could be a text field or a URL field.

    Here is how you could modify the code to include the second field’s value:

    <?php if( get_field('paese', $this->post->ID) ) { ?>
    
    <div class="block-left"><a href="<?php the_field('collegamento', $this->post->ID); ?>"><?php the_field('paese', $this->post->ID); ?></a></div>
    
    <?php } ?>

    I hope that’s helpful and gets you closer to your goal. Let me know!

  • @papijo

    Hey.. sorry for the late reply. I guessed you might know where to put the code because your original question had a function in it. My apologies. It could go in either a custom plugin or in your theme’s functions file as you figured out. I like to use a custom plugin, that way… if ever switching themes… my functions remain. A great way to kick off a new plugin is to use a free plugin called Pluginception. It makes it very very simple to get started… within seconds in fact.

    As for your other statement… it looks like a user setting may be in future plans, just hasn’t found its way into the graphical interface yet. I can’t confirm that though. I’m happy though that you were able to find a reasonable workaround.

  • Did you try using a URL field? Or a text field that you can use to enter a URL?

    You could also have a field that selects an existing category or page… and output the HTML as needed.

    There are a couple different ways to do it… you can choose a field that returns an Object that contains a label and URL… or have two separate fields for that Data for more flexibility. And you can add a 3rd field… a checkbox, asking if the link should open in a new Window..

    Lot of choices.

    Let me know if you need further help.

    p.s. Remember you could use code similar to below to build an anchor tag based on multiple fields:

    <a href="<?php echo get_field('url'); ?>" title="<?php echo get_field('url_title'); ?>"<?php echo get_field('url_new_window'); ?>><?php echo get_field('url_anchor_text'); ?></a>

    The ‘url_new_window’ field can output target=”_blank” (with a leading space if set to TRUE (or checked) )

  • Hi there…

    I ran into something similar before. The closest solution I found was: https://www.bobz.co/dynamically-populate-select-fields-choice-in-advanced-custom-fields/

    This requires JQuery if you don’t want to reload the page…
    You could try a Step 1, Step 2 process… where each Step saves to the DB.. then it’s easier to filter the list in the subsequent step by using ACF filters and PHP…

    It’s doable, but a very advanced topic. Hope that you get it sorted out.

    We might be able to help a piece at a time if you implement many of the steps, and run into any snags along the way.

  • Below is the test code I was playing with. I used variables rather than ACF fields, but you can swap them back out.

    Also… I used || for OR, && for AND, and ! for “not equal to”

    Also… in the last conditional where you check for “One single link”… that won’t trigger when it’s just link 3, because the condition is already met when you output “Link 1 and Link 2 OR Link 3”.

    If you would like to tell me your purpose for the code, I may be able to offer a better solution.

    <?php
    $link1 = '1';
    $link2 = '';
    $link3 = '';
    if ( $link1 && $link2 && $link3 ) {
    
    echo '<div class="red">';
        echo '<p>All 3 Links</p>';
    echo '</div>';
    
    } else if ( ( $link1 && $link2 ) || ( $link3 && !$link1 && !$link2 ) ) {
    
    echo '<div class="blue">';
        echo '<p>Link 1 and Link 2 OR Link 3</p>';
    echo '</div>';
    
    } else if ( $link2 && $link3 && !$link1 ) {
    
    echo '<div class="green">';
        echo '<p>Link 2 and Link 3 But not Link 1</p>';
    echo '</div>';
    
    } else if ( ( $link3 && !$link1 && !$link2 ) || ( !$link3 && !$link1 && $link2 ) || ( !$link3 && $link1 && !$link2 ) ) {
    
    echo '<div class="hotpink">';
        echo '<p>One single Link</p>';
    echo '</div>';
    
    }
    ?>
  • Do you have any Events plugins, or similar, in play that may be playing with the CSS and/or JS for these types of fields? I am still digging… but wondered if you could check that in the meantime.

  • Oh! Ooops… it’s the use of the_field as opposed to get_field when assigning the value to a variable. I should have caught that sooner.

Viewing 25 posts - 76 through 100 (of 118 total)