Support

Account

Home Forums Search Search Results for 'save limit'

Search Results for 'save limit'

topic

  • Unread

    ACF does not save iframe code when entered through a custom user role

    I have a field that echos the iframe code entered by users having role “Business Owner”.

    These users have limited capabilities and can only save, update posts of a custom post type called “”Business Owner Posts”. My ACF fields are visible in such post types only.

    I have noticed that when such users enter the iframe code and try to save it does not get accepted – the field returns empty.

    But the same does not happen when it is entered by users having admin privileges.

    Now, I understand there are security concerns when it comes to iframes but I am sanitizing the entered iframe with regex to ensure they only come from a certain URL and none other.

    So how do I make ACF accept the iframe code as entered by the user type?

  • Helping

    ACF Pro Checkbox Bug? Expects args[‘disabled’] to be an array but it’s 0.

    I’m having issues adding checkbox fields with hard-coded choices (in admin).

    Every time I add a checkbox and adding the choices in admin, I’m getting this error:

    array_map(): Argument #2 ($array) must be of type array, int given

    Checkboxes added using taxonomy field are fine.

    In:
    /advanced-custom-fields-pro/includes/fields/class-acf-field-checkbox.php:247

    This is the code:
    $args[‘disabled’] = array_map( ‘esc_attr’, $args[‘disabled’] );

    ($args[‘disabled’] is 0)

    Here’s the field.:

    {
    “key”: “field_65e14ce0816cf”,
    “label”: “Charts Reporting To”,
    “name”: “charts_reporting_to”,
    “aria-label”: “”,
    “type”: “checkbox”,
    “instructions”: “”,
    “required”: 0,
    “conditional_logic”: 0,
    “wrapper”: {
    “width”: “”,
    “class”: “”,
    “id”: “”
    },
    “disabled”: 0,
    “relevanssi_exclude”: 0,
    “choices”: {
    “Country Aircheck”: “Country Aircheck”,
    “Music Row”: “Music Row”,
    “AMA”: “AMA”,
    “Roots Music Report”: “Roots Music Report”,
    “Bluegrass Unlimited Survey”: “Bluegrass Unlimited Survey”,
    “Bluegrass Today Bluegrass”: “Bluegrass Today Bluegrass”,
    “Bluegrass Today Grassicana”: “Bluegrass Today Grassicana”,
    “Bluegrass Today Gospel”: “Bluegrass Today Gospel”,
    “Singing News”: “Singing News”,
    “Singing News Bluegrass”: “Singing News Bluegrass”
    },
    “default_value”: [],
    “return_format”: “value”,
    “allow_custom”: 1,
    “save_custom”: 0,
    “layout”: “vertical”,
    “toggle”: 0,
    “custom_choice_button_text”: “Add new choice”
    },

    I noticed all ACF fields have disabled set to zero.

    Any help is appreciated.

  • Unread

    Saving block in post meta -> single use only!

    Hello,

    As i just figured out, when using the new feature to save block meta in the postmeta table, the block is limited to single use only (per page/post), even if you add the support attribute “multiple”: true.

    This behaviour should be documented on this page: https://www.advancedcustomfields.com/resources/save-acf-block-values-to-post-meta/

    Thanks!

  • Unread

    ACF fields filled in with XMLRPC will not save

    Hi,

    I am currently working on a few small utility applications to help move data from locally stored files to a locally hosted WordPress site. I am doing this through python-xmlrpc which has worked well up until this point.

    I would like to pre-face this by saying that I do not have access to change any of the theme code or the ACF field settings within the site. I can simply create and edit posts.

    The issue occurs from a post type that only really makes use of the ACF fields given to it and acts like an account database for users (which are separate to the actual WordPress users). When I attempt to create a new post of this post type, it will create a new post and the fields will end up filled but not actually saved to the database. I then need to press the “Update” or “Publish” button manually on the page which will save the data and allow it to be used (since the data acts as accounts, I have tested this by trying to log into the newly made account both before and after manually “saving” the data).

    I am placing the values into the WordPressPost.custom_fields attribute (https://python-wordpress-xmlrpc.readthedocs.io/en/latest/ref/wordpress.html). To do this, I am using the field name rather than the field key which is mentioned in a few other threads. I tried to use the field key to make this work but it would make the post and not actually fill in any data at all.

    Does anyone know why the post will not save just from the xmlrpc call and anyways that you can make that happen?

    I understand that this could just be a limitation of ACF and XMLRPC in which case I have a couple options. One to use Selenium to just simulate the button press but this would be a much slower solution. Another thought I’ve had is to try and perform the same actions that the “Update” button does but externally through my own program. The only thing I’ve found so far is a call to admin-ajax.php, so if anyone has an idea of how that could be replicated that would be very much appreciated.

    I would also like to add that editing posts of this type works perfectly as expected and can even edit the new posts before I have manually pressed “Update”. Although, the new posts will not function as accounts until I have pressed “Update” even after editing through xmlrpc.

  • Helping

    meta_query for relationship field with array of values?

    I’m building an AJAX filtering system and am trying to include a filter that can take multiple IDs and then filter custom post type posts based on its relationship field. Is there any handy method of doing meta_query with an array of values for a relationship field which is saved as array? I’m trying to achieve something like this
    ‘meta_query’ => array(
    array(
    ‘key’ => ‘relationship_field’,
    ‘value’ => serialize([1234, 4321]),
    ‘compare’ => ‘LIKE’,
    )
    )
    Is anything like this doable or is doing multiple OR conditioned meta queries the only option? This probably gets pretty heavy very quickly, so is there best practice on how many you should use, meaning I could probably limit how many IDs can be passed to the filtering function?
    It’s possible to filter out posts that don’t match inside the loop with array_intersect IF statement, but that wouldn’t be very good for pagination.

  • Helping

    need help with repeater

    i have a repeater field , when the post have more that 106 rows i get 404 when trying to save… before i could save more that 100 rows (they have only a few filds inside)

    when i run phpinfo i can see:
    local. master
    max_execution_time 10000 10000
    max_file_uploads 20 20
    max_input_nesting_level 256 64
    max_input_time -1 -1
    max_input_vars 20000 10000
    memory_limit 1G 1G

    i think i change this to this high values… what could it be ? i also tryed :
    /**
    * Increase ACF Repeater row limit
    */
    function my_acf_repeater_settings( $field ) {
    $field[‘max’] = 5000; // Change this value to your desired limit
    return $field;
    }
    add_filter(‘acf/fields/repeater/settings’, ‘my_acf_repeater_settings’);

    no luck .. my acf is Ver5.12.3 … can any kind soul help me? tanks

  • Helping

    Error 500 / 504 on update page with a lot of ACF fields

    We have a page where we use a lot of different ACF custom blocks / fields, including ACF wrappers.

    When we click to update this page, the whole website goes down until its fully saved – which takes half a minute to couple of minutes.

    While the update-button is loading and I go to console on the edit page it will show:
    VM2831:1 GET urlremoved/wp-admin/post.php?post=169&action=edit&message=4 500 (Internal Server Error)

    And if I open new window to see the website during this loading, it will show Database not connected. Sometimes 504 Gateway Time-out.

    The error logs say:
    PHP Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /var/www/urlremoved/wordpress/wp-includes/wp-db.php on line 1753

    Im not sure what to do to not have this happen, we tried increasing some php settings but that didnt help.

    Server:
    File uploads Enabled
    Max size of post data allowed 13M
    Max size of an uploaded file 256M
    Max effective file size 13 MB
    Max number of files allowed 20
    Server architecture Linux 5.4.0-89-generic x86_64
    Web server nginx/1.18.0
    PHP version 7.4.3 (Supports 64bit values)
    PHP SAPI fpm-fcgi
    PHP max input variables 1000
    PHP time limit 30
    PHP memory limit 516M
    Max input time 60
    Upload max filesize 256M
    PHP post max size 13M
    cURL version 7.68.0 OpenSSL/1.1.1f
    Is SUHOSIN installed? No
    Is the Imagick library available? No
    Are pretty permalinks supported? Yes

    Database:
    Database size 208,80 MB
    Extension mysqli
    Server version 8.0.30-0ubuntu0.20.04.2
    Client version mysqlnd 7.4.3
    Database username wp_user
    Database host 127.0.0.1
    Database name wp_stage_db
    Table prefix wp_
    Database charset utf8mb4
    Database collation utf8mb4_unicode_520_ci
    Max allowed packet size 67108864
    Max connections number 151

    Wordpress constants:
    WP_MEMORY_LIMIT 516M
    WP_MAX_MEMORY_LIMIT 256M
    WP_DEBUG Disabled
    WP_DEBUG_DISPLAY Enabled
    WP_DEBUG_LOG Disabled
    SCRIPT_DEBUG Disabled
    WP_CACHE Disabled
    CONCATENATE_SCRIPTS Undefined
    COMPRESS_SCRIPTS Undefined
    COMPRESS_CSS Undefined
    WP_ENVIRONMENT_TYPE Undefined
    DB_CHARSET utf8mb4
    DB_COLLATE

  • Unread

    AJAX Blocks Call

    I have a block that I created and I am looking to update the fields based upon a date range being selected and then having that data update other data that is not touch yed.

    <?php
    
    /**
     * Composite Reports Block Template.
     *
     * @param   array $block The block settings and attributes.
     * @param   string $content The block inner HTML (empty).
     * @param   bool $is_preview True during AJAX preview.
     * @param   (int|string) $post_id The post ID this block is saved to.
     */
    
    // Global Declarations
    global $wpdb;
    
    // Create id attribute allowing for custom "anchor" value.
    $id = 'composite_reports-' . $block['id'];
    if( !empty($block['anchor']) ) {
        $id = $block['anchor'];
    }
    
    // Create class attribute allowing for custom "className" and "align" values.
    $className = 'composite_reports';
    if( !empty($block['className']) ) {
        $className .= ' ' . $block['className'];
    }
    if( !empty($block['align']) ) {
        $className .= ' align' . $block['align'];
    }
    
    // Load values and assign defaults.
    $trainee = get_field('trainee_name') ?: 'Traine Name...';
    $date_from = get_field('date_from') ?: date("01/01/2020");
    $date_to = get_field('date_to') ?: date("m/d/Y");
    $desktop_limit = get_field('desktop_limit') ?: 1000;
    $mobile_limit = get_field('mobile_limit') ?: 5;
    
    // echo $trainee . '<br>';
    // echo $date_from . '<br>';
    // echo $date_to . '<br>';
    // echo $desktop_limit . '<br>';
    // echo $mobile_limit . '<br>';
    
    $procedureDates = [];
    $traineeScores = [];
    $attendingScores = [];
    
    echo $trainee;
    
    // Composite Report Data Queries
    
    $results = $wpdb->get_results("SELECT * FROM (SELECT t1.traineeName, t1.procedureDate, t1.surgeryID, t1.traineeRemovesFatAdrenalRating, t1.traineeSkeletonizesRenalVeinRating, t1.traineeSkeletonizesArteryRating, t1.traineeDonorArteriesRating, t1.traineeRenalVeinAugmentationRating, t1.traineeOverallPerformanceRating, t2.doctorRemovesFatAdrenalRating, t2.doctorSkeletonizesRenalVeinRating, t2.doctorSkeletonizesArteryRating, t2.doctorDonorArteriesRating, t2.doctorRenalVeinAugmentationRating, t2.doctorOverallPerformanceRating FROM BackbenchKidneyChartTrainee t1 JOIN BackbenchKidneyChartDoctor t2 ON t1.traineeName = t2.traineeName WHERE t1.surgeryID = t2.surgeryID AND (t1.traineeName = '" . $trainee . "' AND t2.traineeName = '" . $trainee . "') AND " . date(t1.procedureDate) . " BETWEEN '" . $date_from . "' AND '" . $date_to . "' ORDER BY t1.surgeryID DESC LIMIT " . $desktop_limit . ") t3 ORDER BY t3.surgeryID ASC");
    //STR_TO_DATE(, '%m/%d/%Y')
    
    $overallResults = $wpdb->get_results("SELECT * FROM (SELECT t1.traineeName, t1.procedureDate, t1.surgeryID, t1.traineeOverallPerformanceRating, t2.doctorOverallPerformanceRating FROM BackbenchKidneyChartTrainee t1 JOIN BackbenchKidneyChartDoctor t2 ON t1.traineeName = t2.traineeName WHERE t1.surgeryID = t2.surgeryID AND (t1.traineeName = '" . $trainee . "' AND t2.traineeName = '" . $trainee . "') AND STR_TO_DATE(t1.procedureDate, '%m/%d/%Y') BETWEEN STR_TO_DATE('" . $date_from . "', '%m/%d/%Y') AND STR_TO_DATE('" . $date_to . "', '%m/%d/%Y') ORDER BY t1.surgeryID DESC LIMIT " . $desktop_limit . ") t3 ORDER BY t3.surgeryID ASC");
    
    $overall = json_encode($overallResults);
    
    if ( ! empty( $overallResults ) ) {
            foreach($overallResults as $row) {
    				array_push($procedureDates, "'" . $row->procedureDate . "'" );
    				array_push($traineeScores, $row->traineeOverallPerformanceRating);
    				array_push($attendingScores, $row->doctorOverallPerformanceRating);
            }
        }
    
    // print_r(array_values($procedureDates)) . '<br>';
    // print_r(array_values($traineeScores)) . '<br>';
    // print_r(array_values($attendingScroes)) . '<br>';
    
    $procedureDate = implode(', ', $procedureDates);
    $traineeScore = implode(', ', $traineeScores);
    $attendingScore = implode(', ', $attendingScores);
    
    ?>
    
    <script type="text/javascript">
    
    jQuery(function() {
      var chart = jQuery('#container').highcharts({
        chart: {},
    	title: {
        	text: 'Overall Performance'
    	},
        xAxis: {
          categories: [<?php echo $procedureDate; ?>]
        },
    
        yAxis: {
    	min: 1,
        max: 4,
        title: {
          text: 'Values'
        },
        plotLines: [{
          
    	}]
      },
    
        legend: {
    	  enabled: true,
          align: 'center',
          verticalAlign: 'bottom',
          x: 0,
          y: 0
        },
    
        credits: {
          enabled: false
        },
    	  
    	exporting: {
        	enabled: false
      	},
    
        series: [
    	{
        	name: 'Trainee',
        	data: [<?php echo $traineeScore; ?>]
      	},
    	{
        	name: 'Attending',
        	data: [<?php echo $attendingScore; ?>]
      	}]
      }, function(chart) {
    
      });
    
    });
    	
    </script>
    
    <div id="<?php echo esc_attr($id); ?>" class="<?php echo esc_attr($className); ?>">
        <div id="container" style="height: 400px"></div>
    
    </div>

    ;

  • Solved

    Fields are randomly not saved

    Cross post from wordpress support page

    In a shop I am working on, I created a few custom fields associated to the product post type. I have a strange issue that cannot debug further. When I publish or update the product, some of the custom fields stay empty (not updating).

    What I did for debugging:

    – Disabled all the plugins except Woocommerce and ACF
    – Changed theme to storefront
    – Disable server and website cache
    – Check server logs (nothing there)
    – Enable wp_debug and also nothing
    – Disable every custom code I had in the child theme

    What I also found:

    – The name doesn’t matter. I created a field called “Box Quantity” and I couldn’t save it. Then I delete all the custom fields and create just this one and it worked. Adding more kept this one working but not the new fields
    – Checked the database on the postmeta table and the fields values are not there. So not saved at all.

    Those are some of the server settings that might affected it. As you see, values are big enough and I even tried to increase them more with no success.

    
    PHP version	7.2.34
    PHP max input variables	6500
    PHP time limit	3600
    PHP memory limit	3072M
    Max input time	1000
    PHP post max size	260M
    WordPress Version 5.8.2
    Advanced Custom Fields Version 5.11.4
    WooCommerce Version 6.0.0
    
  • Solved

    Heavy Usage Of ACF

    Hi everyone here is my situation and question for ACF community,

    I am using ACF to make a fairly large web-app, I have 40-50 custom post types and more than 1000 custom fields in total.

    Today I am making the heaviest of the post types which has nearly 300 custom fields (those fields include calculated fields, repeater fields, pre-loaded fields if I have to count the repeater fields it’s probably more than 4000 fields in total)

    When I get past 100 fields my app started to miss some values on saving, when I save 50-60 custom fields at once, some of them didn’t save. That one time some conditional logics disappeared from my field group all of a sudden.

    So my question is, is there a limit what you can do with ACF? Or is it about my hosting plan&provider? What happens when I try to save 1000 fields at once with acf_form from the front-end app?

    Is there any other people out there making this kinda heavy projects with ACF PRO?

  • Solving

    Object Cache not working @ SiteGround

    On my server at Siteground I am using SG optimizer.

    I have to do a complete manual flush for every change to a post or a new post. Without this manual flush, changes will never be visible on my site.

    The problem is that an item added within ACF Pro (with a registered post-type) in the WP-admin looks like it’s not giving a signal to the object-cache. That way there is never a cache flush like when you save a wp-post or page. Is there a way to achieve the same result as when we’re saving a wp-item?

    I already made a support ticket. ACF confirmed the issue, but has no solution at the moment:

    Patrick Mwange replied
    Hi there,

    Thanks a bundle for the clarification. I now understand the challenge with SiteGround.

    Unfortunately, I’m afraid there is currently no option out of the box from the ACF end to resolve this limitation. I’m going to share the same with the dev team as well for further consideration.

    In the meantime, I would recommend that you also open a forum thread on the same. Someone else may have implemented a custom solution that might.

    My apologies for the inconvenience.

    Maybe someone has a possible solution/workaround already?

  • Solving

    WYSIWYG always defaults to text mode

    Users editing custom post types with ACF WYSIWYG’s on the screen are always defaulting to the “Text” tab. Changing to another tab does not seem to save as the default. This is a recent problem that seems to only be limited to users within a new user role we created that has the following capabilities:

    Copy posts, create posts, delete others posts, delete posts, delete private posts, delete published posts, edit others posts, edit posts, edit private posts, edit published posts, manage categories, moderate comments, publish posts, read, read private posts, unfiltered upload, upload files

    Admins and editors are not having a problem. Any advice on how to fix or troubleshoot this? Thanks!

  • Solving

    ACF 5.8.13 (Free) + WP 5.4.2 – Cannot add more than 10 fields to a field-group

    Hello,

    I am trying out the ACF 5.8.13 (Free) version on WordPress 5.4.2. This is a local machine install on Ubuntu + MySQL 8.0.21.

    The problem is that I am unable to add more than 10 (ten) fields to a field group. When I add an 11th field and hit the UPDATE button, the message alert on the top says that the fields have been saved. But, when the field-group refreshes, it only has the first 10 fields.

    What I have tried:

    1. Create a fresh field group that is not bound to any post type (post type query is blank).

    2. Created a field-group, added 10 fields, exported it to JSON (using the Custom Fields > Tools > Export Field Groups), added the 11th field to it using a text editor. Deleted the original field group from WP-ADMIN, cleared it from Trash as well. Imported the modified JSON using the Custom Fields > Tools > Import Field Groups.

    I also attempted to trace through the code to figure out what was going on, but with so many filters and nested logic, it was kind of hard to get anywhere. However, I did confirm that both the acf_update_field() and acf_update_field_group() functions were doing their job. In both cases, the fields were reported as committed to the database.

    Interestingly, I can see that in the WP_POSTS table in the database, these fields ARE PRESENT. But they do not show up on any UI !

    Is this a limitation of the free version?

reply

  • It would be more complicated than that and using a user would be of limited use.

    Let’s say that you want a page separate from the user profile page to store additional user values. You could dynamically set the user where the values are save to for an options page based on the currently logged in user. Only one such page would ever be available and only the currently logged in user would be able to view or edit the values.

    I haven’t got a clue what use case would involve saving values to specific term.

    However, getting values from meta is generally faster than getting values from options unless you have the options set to autoload.

    I generally use the last option. This allows me to keep different options for different options pages separated in the options table and allows me to have the same field names used on multiple options pages because the option_name value varies by option page.

  • Adding terms to a taxonomy requires the WP manage_categories permission.

    Your choices are limited.

    You could edit roles and give everyone this permission, but that’s probably not a good choice.

    I might be possible to give this permission temporarily when viewing a specific page. I’m now 100% sure about this or how it can be done.

    And the last choice is to include a separate text field that is only shown when a user does not have the correct permission using the acf/prepare_field filter and then adding an acf/save_post filter that will add the term to WP and then set it as a post term.

  • I assume you mean if you have a taxonomy under WooComm, you are saying that you have a product post type with a new taxonomy of Brand, right? And then each term in that taxonomy (Brand A, Brand B, Brand C) has a field that has a shipping time associated with it. And that you have found some way (there are a few methods) to limit each product to a single brand term. Yes?

    Then I am not sure why you would want to copy this field elsewhere – would you not just use it in the original location? (Having the same data in 2 places just invites it to be wrong somewhere.) You can pull out the information using this:
    https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/

    If you really want it in 2 places, you can also use that method to pull out the taxonomy term field value and stuff it into an update_field on the acf/save_post hook.
    https://www.advancedcustomfields.com/resources/acf-save_post/
    See the “applied after save” section and then
    https://www.advancedcustomfields.com/resources/update_field/

  • You cannot add WYSIWYG buttons to that field. This functionality is only available for the WP description field when you view the media library in list view and then edit the image details in the WP admin. This functionality is not available when viewing/editing in grid view and is a limitation of this view in WP. ACF uses the the build in WP image selector and editor for the gallery field for the grid view.

    The value of the description field for attachments is saved in the “post_content” column of the “_posts” table

    You can accomplish this by adding a field group to the media (attachment) post type with a WYSYWYG field with a basic toolbar and then creating an acf/save_post action for attachment post types that copies the value of your custom field to post_content.

  • Seems like this might be limited to textareas on nav menu items. I can save <svg> code just fine if I add it to a textarea in other locations, like on a Post.

  • You are correct. You cannot limit where individual fields are shown, only entire field groups.

    It is possible to limit where a specific field is used by using an acf/prepare_field filter to remove fields that should not be shown. You would need to use the “field key” variant of the filter and you would need to determine for yourself when the field should be shown or not.

    In all likely hood it would mean saving the post to become effective. For example, if a location rule is based on a taxonomy term then the post would need to be saved with that taxonomy term before you would be able to test for that taxonomy in your filter function. The same would apply to any setting that is generally controlled by WP.

    This could be overcome by moving all WP settings into custom fields, you could then use conditional logic based on these new custom fields instead of the above filter. However, this would mean creating an acf/save_post action to convert all of the new controls into WP setting when the post is saved. This may also not be possible in all cases.

  • Hi I will try to explain my proposal
    http://joxi.ru/1A5YVjkUw3vaWA
    I have a problem when a content manager is lazy person and don’t want to write 2-3 paragraphs for short description of post (I made it by ACF field). I want change this problem like a developer. I’m solving this problem, but in a bad way and you could help fix it =)
    Can you please change the field ‘Character Limit’ and make <input type=”range”> instead of <input type=”number”>. If you make a change, it will help users to set not only the upper limit of the available characters, but also the lower limit. This value, in my understanding should have two values, – min value and max value. By default let it be 0 value in both meanings.

    – min value number can’t be more than max value number. (but if max value===0 it’s OK)
    – if field will be Required, person can’t save file if numbers of symbols will be less than the specified value

    I hope you will consider my suggestion and be able to implement it in the next version of the plugin. Thanks

  • Understood, thanks John.

    Would allocating more resources help the server save the data quicker so the timeout doesn’t happen? I can increase the memory and CPU limit of the hosting server.

  • Hi John

    Thankyou for getting back to me. I have read tons of your ACF work and use a couple of your plugins. I’m very grateful to you for posting a reply.

    Yes that is exactly what I’m trying to do; and are well in over my head! I’ve attached a JPG which probably explains it better. The area in blue is the parent “listing” post. In green are related viewing appointment times: “events.” In orange is an ACF form with a “booking” post. Within the booking post in purple is a related “events” field. Purple is supposed to allow the user to choose from the available event times (as seen in green). Purple currently lists all booking times posted for all events.

    At the top you can see a shortcode return: 207 is the ID of the listing (Blue) and the array 3515,4562 are the events times (green). I cannot seem to get the array loaded in the ACF [acf/fields/post_object/query/] filter. The post ID (207) comes back empty when in called inside the filter.

    I’ve tried using a global var to save the ID but this also seems to zero out.

    I’m beyond the limits of my present knowledge on how to fix this.

    Some other files also attached which you can take credit for and use as you see fit 🙂

  • I know this is a bit late but I just had this same issue I was trying to solve. I managed to get a working proof of concept by Frankensteining a number of different tutorials together. I have an ACF field on the custom post type page called ‘homepage_order’ that I can enter data in and if I go to the posts list page I can see that content in a custom column and update the content from the Quick Edit box of each post. I am not a proficient PHP coder so I’m sure there are glaring errors and my security checks are not all there (some of them are causing the update to fail) but hopefully this will help point you in the right direction. If anyone has any comments on how I can make this better, I would be most appreciative.

    
    //Adds the custom column to the exhibits posts list page
    add_filter( 'manage_exhibits_posts_columns', 'heard_filter_posts_columns' );
    function heard_filter_posts_columns( $columns ) {
      $columns['homepage_order'] = __( 'Current Exhibits Order', 'heard' );
      return $columns;
    }
    //Gets the data from the custom field populated in the exhibits post and adds it to the column
    add_action( 'manage_exhibits_posts_custom_column', 'heard_homepageorder_column', 10, 2);
    function heard_homepageorder_column( $column, $post_id ) {
      // Image column
      if ( 'homepage_order' === $column ) {
        echo get_post_meta( $post_id, 'homepage_order', true );
      }
    }
    //Creates a fillable field in the Quick Edit box
    add_action( 'quick_edit_custom_box', 'heard_custom_edit_box_pt', 10, 3 );
    function heard_custom_edit_box_pt( $column, $post_id ){
    
    if($column == 'homepage_order'){
        $html .= '<fieldset class="inline-edit-col-right ">';
            $html .= '<div class="inline-edit-group wp-clearfix">';
                $html .= '<label class="alignleft" for="homepage_order">Current Exhibits Order</label>';
                $html .= '<input type="text" name="homepage_order" id="homepage_order" value="" />';
            $html .= '</div>';
        $html .= '</fieldset>';    
    }
    
    echo $html;
    }
    //Saves any updates to the current exhibit order field in the Quick Edit box
    add_action( 'save_post_exhibits', 'heard_update_custom_quickedit_box' );
    function heard_update_custom_quickedit_box() {
      //There are currently limited security measures in place on this. The quick edit field won't update when I add all of them. Still working on this.    
      //Check user permissions- this works
    if ( 'page' == $_POST['homepage_order'] ) {
            if ( !current_user_can( 'edit_page', $post_id ) )
                return $post_id;
        }
        // save homepage_order updates in Exhibits- custom post type
        if( isset( $_POST['homepage_order'] )) { // where homepage_order is defined in the <input name="homepage_order">
            update_post_meta($_POST['post_ID'], 'homepage_order', $_POST['homepage_order']);
        }
        return; // finish the function call
    }
    
  • I don’t know if this will help you or make your dev process any easier. My goal when I build a site has to do with making things easy for the client and not necessarily making it easier for myself, so when I’m building the admin for the client I don’t even give much thought to how difficult it will be for me to code, I just make sure that it’s something that can be coded. However, I do my best to never code something more than once.

    I build in “modules” I have a field group that has all the settings I need for links, not only the ones you mention but others. I then clone this field group as the only sub field of a “Group Field”, this insures that all fields of my group are always “sub fields” With this in place I have a single template part file that is called to output links.

    
    // something like this goes into my template
    if (have_rows('group_field_name')) {
      // always true for a group field that exists
      while (have_rows('group_field_name')) {
        // always executes once for group fields that exist
        get_template_part('template-parts/components/link);
      }
    }
    

    So I have only coded this once. My group has become quite complicated, but if changes are made I only need to make them in a single file.

    The field group for links can also be cloned as the only sub field in a repeater and the template part file will still work but allow the client to add multiple CTA buttons.

    I actually use a true/false field the new window setting. The label on the true false field is
    – Same Window = false
    – New Window = true
    and the code in my template part for building this part of the link button is

     
    $target = '';
    if (get_sub_field('target')) {
      $target = ' target="_blank"';
    }
    

    and example of my link output

    
    <a href="<?php echo $url; ?>" class="<?php echo implode(' ', $cta_classes) ?>"<?php echo $title.$rel.$target.$onclick; ?>><?php echo $text; ?></a>
    

    Also, when it comes to a URL and the client entering a URL, I do not use a URL field because it is too limiting. For example lets say that you want to allow the client to enter anything other than a URL. My clients and the people I work with want to be able to enter anchor links as well as tel:, mailto:, sms: and ftp: links. So instead of using a URL field I use a text field with custom validation. Building separate fields would increase the code and complicate things for the client. Instead I have a text field that will accept anything that appears to be a valid href value and as part of the client’s instruction when handing over the site they are shown how to use this field and the field has very good instructions to help remind them.

    
    add_filter('acf/validate_value/key=field_XXXXXXXX', 'validate_text_as_href', 20, 4);
    function validate_text_as_href($valid, $value, $field, $input) {
      // this allows links starting with
      // / (site root relative), http://, https://, ftp://, # (anchor), mailto:, tel:, sms:
      if (!$valid) {
        return $valid;
      }
      if (!empty($value)) {
        if (!preg_match('%^(https?\://|ftp\://|/|#|mailto\:|sms\:|tel\:)%', $value)) {
          $valid = 'Enter a Valid HREF Value';
        }
      }
      return $valid;
    }
    

    As to automatically updating or redirection, I have not built anything that will automatically redirect if the slug of a page is changed. I will need to look into that, what I do know is that what is built into WP rarely works as expected.

    As far as automatically updating links when a slug or url changes, you would need to keep some type of history on the slug/url of the page when it is updated. You would need to add a pre_post_update action that somehow checks to see if the url of the page is being changed. If it is then you’d have to figure out how to lookup and changed all of the other posts and pages where there is a link to the page being updated and change them without this process timing out the admin page refresh. This would basically mean that you’d have to record somewhere/somehow all of the places where a link to the page is saved to allow a quicker lookup so that they can be found quickly and updated.

    This brings me back to the automatic redirection because the testing to see if the URL has changed for a page sparked an idea. You could as in the above add a pre_post_update action and if possible record a history of all of the URLs that were ever assigned to this post and then on a 404 you could do a search for posts that have had the missing URL. This isn’t actually a bad idea that I may look into.

  • I would have to agree with @johnbarneson

    You’re talking about rebuilding all of the templates and moving content. It will rarely be cost effective to make the change automatically or creating a import tool to do this when it will happen exactly 1 time. My experience is that it will take longer to build the tool, make sure it work and then use it than it will take so simply update the data manually.

    If I had to do this on a budget and the number of fields was extremely limited I would

    1) Create my new acf field groups.

    2) At each location where a “simple field” was used I would see if the acf field has content and if not then use the existing simple fields code

    
    if (get_field('some-field')) {
      // data exists in the new acf field
    } else {
      // no data in acf field
      // existing simple fields code here
    }
    

    3) The next step I would take is to add an acf/prepare_field filter for every acf field that needed to use the simple fields data. In this field I would test for a value in the field. If there is no value then I would get the simple fields field value. What this does it that it will copy any existing data when and if someone edits an old page.

    4) As an added step I would create an acf/save+post action that deletes all the data stored by simple fields whenever a post us updated.

Viewing 25 results - 1 through 25 (of 148 total)