AdvancedCustomFields / acf

Advanced Custom Fields
http://advancedcustomfields.com/
871 stars 182 forks source link

Custom Post Type `menu_order` always set to 0 when saving as JSON #878

Open tech-knowledgy opened 1 year ago

tech-knowledgy commented 1 year ago

Describe the bug Whether manually exporting as JSON, or using the acf/settings/save_json filter, menu_order always reverts to 0

To Reproduce Steps to reproduce the behavior:

  1. Go to Post Types
  2. Create new Post Type, and set custom Menu Order under the Advanced > Visibility tab
  3. Save via filter or manually export JSON on Tools page
  4. See menu_order is 0, although UI reflects correct value

Expected behavior JSON Should 100% reflect what's stored in the database.

Code Straightforward filter usage based on docs:

$ACF_CUSTOM_SAVE_PATH = './acf-settings';

function acf_save_json($path)
{
    global $ACF_CUSTOM_SAVE_PATH;
    return get_stylesheet_directory() . $ACF_CUSTOM_SAVE_PATH;
}

Version Information:

mattgrshaw commented 1 year ago

Hi @tech-knowledgy, thanks for the report. We've been able to replicate this and will get it fixed up in a future release.

mattgrshaw commented 1 year ago

@tech-knowledgy Just to clarify, the menu_position parameter is actually what's used to save the "Menu Position" setting and set the position of the CPT in the menu, and in my testing that appears to be set correctly in the JSON files.

The menu_order param is internal to ACF and is at the moment unused, so we may end up removing that from the JSON export to prevent confusion. This tripped me up for a minute as well!

tech-knowledgy commented 1 year ago

When another dev imports the JSON file, it isn't keeping order based on what another dev has instructed the CPT order to be. When hand-massaging this value in the JSON and then importing, it does keep the correct value.

Because the JSON file will always render out a 0, it isn't appearing to import properly without this manual file manipulation.

The end goal is to ensure the order is consistent among all devs based on the JSON file since it's configured through ACF and saved to disk through the ACF filter.

mattgrshaw commented 1 year ago

@tech-knowledgy by CPT order, are you referencing where that CPT shows up in the sidebar on the left?

If so, that should be the menu_position param rather than the menu_order param. Does the menu_position param show up in your JSON file, and is that 0 as well?

tech-knowledgy commented 1 year ago

Yes, where they appear in the sidebar on the left.

menu_position does not seem to be honored after the value 4.

1 - Very top (above Dashboard entry) 2 - Just below Dashboard entry 3 - Same visible location as 2 (likely replacing a non-visible separator) 4 - Far down in 9th spot

This item positioned in spot 4 is far below other CPT's created by ACF that have higher valued menu_position settings (we have up to 9 so far).

However, as stated in the original post, as well as in the follow-up, manually manipulating menu_order, regardless of what menu_position holds, resolves the issue. But as soon as we make any changes to the CPT, the value is reset to 0, and order is jumbled up in a nonsensical manner. I'm sure there is sense to it, but it's certainly not honoring the values we set to them. In fact, we can intentionally change menu_position in the JSON files by hand and as long as menu_order is correct, it is indeed ordering as we expect.

This test can be performed on a brand new install of Wordpress 6.3.1, ACF Pro 6.2.1.1, literally no code changes, default WP theme, and you don't even have to import/sync the JSON files to see the effects. I've attempted to create CPTs from scratch and get the same result.

I searched the source and only see menu_position referenced twice: once for the Advanced Options UI, and the other when establishing $args for a filter of acf/post_type/registration_args.

Maybe I'm blind or my search-fu is failing me, but I don't see this filter being utilized anywhere - so the fact it is updating to some degree kinda baffles me, but I don't know the deep internals of ACF nor pretend to.

However, when I searched the source for menu_order, I do see it referenced significantly more.

I'm not sure what to tell you other than to attempt creating a handful of CPTs and adjusting their order, and you shouldn't see the values you set honored correctly.

On an aside, the order not being honored also holds true for Field Groups that are set as Side for a Advanced > Presentation > Position, but that's not as pressing for us at the moment. I haven't tested order in the Normal (after content) setting as they're appearing in the order added to the Field Group which is fine-enough for us at the moment.

tech-knowledgy commented 1 year ago

Here's what it looks like when I create 4 entries, named Pos 4->7 and given those exact menu_position values: image

Attached is the JSON as it is exported from the UI acf-export-2023-09-21.zip