-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrating from custom system, and not able to keep the order in authors. Wrong sorting. #1052
Comments
Regular posts also doesn't respect the sorting option from post editing screen (gutenberg + hybrid theme) |
@bystrzan While I was debugging this issue, I noticed that the AJAX call made in the post editor also uses add_coauthors. |
@manuelRod by any chance, do you still see the same thing happening if you used this PR? |
TL;DRThe issue stems from WordPress Core function Co-Authors Plus does have its own ordering mechanism but that does not work when adding terms that don't already exist for a particular post programatically / via CLI. The ordering does work when the Post Editor interface is used. The command does fix the ordering on a second run since all the authors required for a post already exist (even if they were in the wrong order after the first run). Code: Co-Authors-Plus/php/class-coauthors-plus.php Line 1011 in 1c29766
References:
LOCAL TESTINGSo as a proof of concept, I booted up a WordPress instance using Local (https://localwp.com/). I activated Twenty-Twenty Two theme, and added the following code snippet in that theme's functions.php:
Once I added that, I dumped the output as follows:
I then modified the wp_set_post_terms line to:
However, now when I dump the terms for this post:
The already existing term from the array test is NOT first even though I explicitly mentioned test as the first entry. So that means WHAT HAPPENS IN CO-AUTHORS PLUSCo-Authors Plus has an additional field that it uses to maintain order AFTER the terms are added. This column term_order already ships with WordPress Core as part of the WordPress Core Database Description: https://codex.wordpress.org/Database_Description The issue stems from This is how WordPress Core does it, and it does make logical sense, as one cannot know the custom order of a term in isolation during an insert, and the sort will fallback to being alphabetical or by Any custom ordering step, if needed, has to be an additional step AFTER the terms are assigned to a post. **Co-Authors Plus does not cause order mismatch when using the ordering interface on the Post Editor pages, since order is passed via the custom metabox, which is presumably hooked into other actions preserving the order, presumably using the In the context of your custom command, however, Co-Authors Plus abides by how WordPress Core allows it to set terms, which is without any order, and requires an additional step AFTER the terms are assigned for re-ordering, since there are no metaboxes or TEMPORARY SOLUTIONWhen using the method GOING FORWARDI am currently exploring the possibility of integrating order verification into the Co-Authors Plus plugin. This process may take some time as I need to familiarize myself with the project's codebase to determine the feasibility and optimal placement of this feature. Should this integration prove feasible, I will submit a pull request and provide a link to it in this thread. |
Hello,
We are currently migrating from another custom system to co-authors.
We are having a lot of trouble with the migration since the ordering of authors seems to be completely random.
Sometimes (most of the time) respects the old order, but sometimes it doesn't.
Maybe the way we are doing it it's wrong (?)
How are we doing it?
Passing an array of authors (with user_nicename) to add_coauthors function.
Sometimes we will get co-authors in the right other, sometimes inverse.
Why the order is sometimes not respected? I tried other combinations, like calling add_coauthors with just one author, n times. Nothing seems to work, and all the time seems random.
Any clues? Are we doing it wrong?
Thanks,
The text was updated successfully, but these errors were encountered: