Hi Giovanni,
I verified the issue you were facing.
The data is stored correctly in the database. The front-end shows this data. So, nothing wrong here ??
However, on the back-end, before The SEO Framework can show its meta box, the meta fields seem to be inaccessible.
The issue seems to be that Advanced Classifieds and Directory Pro overrides the global post object to the custom field present.
So, say your custom field has a post ID 4, but the post you’re editing is post ID 9, then you’ll save for 9, but retrieve for 4 on the subsequent request.
@pluginsware Please advise–and no, not Yoast SEO! D:
The root cause of this issue is somewhere in the query loop at (or right before) ACADP_PLUGIN_DIR . admin/partials/listings/acadp-admin-custom-fields-display.php
, whereafter get_the_ID()
returns the value of the last post processed.
To resolve this issue, the global $post
object variable needs to be restored. Restoring the $post
value by global reference did the trick for me, but another solution might be preferable. I marked my edits of the code below with // Sybre edit
.
Now, oddly, I couldn’t get wp_reset_postdata()
to do what it was supposed to do–perhaps because there’s no initial loop present in the edit screen for it to fall back on. See WP_Query::setup_postdata().
// Ref: ACADP_Admin_Listings::ajax_callback_custom_fields()--somehow runs at non-ajax...
// Start the Loop
global $post;
$cached_post = $post; // Sybre edit: Cache post.
// Process output
ob_start();
include( ACADP_PLUGIN_DIR . 'admin/partials/listings/acadp-admin-custom-fields-display.php' );
$post = $cached_post; // Sybre edit: Restore post.
// wp_reset_postdata(); // Restore global post data stomped by the_post() // Sybre edit: Now redundant, never worked.
$output = ob_get_clean();