Tagged: post-relate
- This topic has 10 replies, 3 voices, and was last updated 6 years, 3 months ago by
mcmaster.
-
AuthorPosts
-
-
October 31, 2015 at 12:50 am #4800
mcmasterMemberI just realized that a site I upgraded to Piklist about a week ago lost all its post relationships. I know that I went through the upgrade script as all of the add-more arrays were converted.
There is still a wp_post_relationships table with 224 entries. It won’t be difficult to write a script to convert these to postmeta entries. So that’s my plan unless you have a better suggestion.
Hope NYC is treating you well!
Donna
-
October 31, 2015 at 1:02 am #4801
mcmasterMemberI just saw another post https://piklist.com/support/topic/how-are-post-relationships-stored/ which indicates that the post-relate data was stored in a table called
wp_piklist_cpt_relate. However, this table wasn’t present in the current DB or in my backups.The metabox code, FYI:
/* Title: Related Projects Post Type: page Description: list of projects related to this page */ piklist('field', array( 'type' => 'post-relate', 'scope' => 'project', 'template' => 'field', 'field' => 'related_project', 'label' => 'Related Projects', ));And the code to retrieve the pages related to a specific project:
$args = array( 'post_type' => 'page', // Set post type you are relating to. 'posts_per_page' => -1, 'post_has' => $post->ID, 'suppress_filters' => false, // This must be set to false ); $list = get_posts( $args ); -
October 31, 2015 at 1:49 pm #4807
KevinKeymaster@mcmaster-
The current table is wp_post_relationships (wp_piklist_cpt_relate is the legacy table) and thats where the data in the migration is pulled from. Try running the upgrade script on the latest version and let us know if the problem persists.
Thanks,
Kevin
-
November 1, 2015 at 2:22 pm #4813
mcmasterMemberIs there a way to run the upgrade script without going back to a previous version of Piklist and then upgrading again?
Also, I don’t want the add-mores to be re-converted, so I’m thinking the best plan is to temporarily remove those files from Piklist parts folders during the upgrade.
Thanks,
Donna -
November 1, 2015 at 10:25 pm #4816
mcmasterMember@Kevin, you really need a way to manually trigger updates!
My first try:
– removed the add-more files from piklist/parts/meta-boxes, leaving just the post-relate fields
– replaced plugin files for 0.9.9.5 with 0.9.4.29
– went into Piklist settings so that it theoretically knew it was running 0.9.4.x
– replaced files for 0.9.4.29 with 0.9.9.5
– back to Piklist settings
– nothing2nd try:
– removed the whole piklist subdirectory from my theme so I could deactivate Piklist
– deactivated 0.9.9.5
– replaced plugin files for 0.9.9.5 with 0.9.4.29
– activated 0.9.4.29
– deactivated 0.9.4.29
– replaced files for 0.9.4.29 with 0.9.9.5
– replaced the piklist subdirectory into my theme
– activated 0.9.9.5
– nothing3rd try:
– removed the piklist subdirectory
– deactivated 0.9.9.5
– replaced plugin files for 0.9.9.5 with 0.9.4.29
– replaced the piklist subdirectory into my theme
– activated 0.9.4.29
– edited a page with the post-relate fields (they are there)
– removed the piklist subdirectory
– deactivated 0.9.4.29
– replaced files for 0.9.4.29 with 0.9.9.5
– replaced the piklist subdirectory into my theme
– activated 0.9.9.5
– edited a page with the post-relate fields
– nothingThat’s not counting the times that I forgot to remove or replace the piklist parts files. 😉
So I studied the Piklist code. I edited
Piklist_Admin::check_updateline 719 to always be true, andPiklist_Admin::get_updateline 799 be true for version number ‘0.9.9.’ This forced Piklist to offer me the update. For some reason it displayed everything twice, but otherwise seemed to run fine. It did not list the post-relate field in its output report (see image), but I now have the post relationships back.Donna
Attachments:
You must be logged in to view attached files. -
November 1, 2015 at 10:48 pm #4818
mcmasterMemberSo the good news is that I can see the post relationships field when editing a page. The bad news is that when I try to retrieve using the legacy code, I get nothing back. Was there a change? Does it now need a field name? Or ??
Again, this is what I have been using, and what worked until 0.9.9:
$args = array( 'post_type' => 'page', // Set post type you are relating to. 'posts_per_page' => -1, 'post_has' => $post->ID, 'suppress_filters' => false, // This must be set to false ); $list = get_posts( $args ); -
November 1, 2015 at 11:12 pm #4819
mcmasterMemberBreakthrough! I accidentally discovered that when I updated (saved) a page, suddenly the related projects appeared on the page. Likewise, the project page now lists that one page. So I’m going to update all the pages and see if the rest of the data shows up.
-
November 1, 2015 at 11:13 pm #4820
mcmasterMemberp.s. saving a copy of the database first and can provide it to you if it might be helpful in diagnosing the problem
-
November 1, 2015 at 11:48 pm #4821
mcmasterMemberOkay, updated all the pages and now the project <-> page relationships are restored on all pages and single projects.
-
November 2, 2015 at 12:03 pm #4827
-
November 2, 2015 at 2:42 pm #4832
mcmasterMember@Steve, here’s what I know. My client has a lot of projects. The singleton projects are not in the navigation; they’re accessible only via pages that reference related projects. The relationship is configured on the pages (code above).
1) I upgraded to 0.9.9 in order to fix a previous Piklist bug, and tested that locally. The new code worked great. However, a few days later I realized that the related projects were no longer being displayed.
2) The projects were still in the wp_post_relationships table. I went in to edit a project, which has a field that displays a list of related pages. The list was empty. I also went in to edit some pages, and I THINK that their lists were also empty, but in retrospect I may have been mistaken about that.
3) I ran the update code (see above). After this, the page editor did show the correct lists of posts. As I said, this may have also been the case before running the update.
4) But on the front end, get_posts() still returned empty results for both post_belongs and post_has queries.
5) I was pretty frustrated and decided to just rewrite the code to do my own post relationship. But in the process of looking at the pages, I had fixed a typo and saved it. Later I noticed that this page was now displaying the project list on the front end. Checked the projects, and each was displaying its relationship with that page but not with other pages it was related to. So I clicked the Update button on another page, and its projects showed up. I then went through and Update’d all the pages and now the projects are all back in view.
Conclusion: I don’t think divine intervention accounts for any of this. The update code (2,3) may have been a red herring. But (1) and (4) were not a problem with my code. It was working fine before upgrading to Piklist 0.9.9, and I made no changes to it. Hopefully (5) provides a clue to what the problem was.
I can provide copies of the database at each stage if that’s helpful. Or let me know what you need.
Regards,
Donna
-
-
AuthorPosts
- You must be logged in to reply to this topic.