Skip to content
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

Handling archiveless posts in Elasticsearch queries #62

Closed
renatonascalves opened this issue Nov 3, 2023 · 0 comments · Fixed by #64
Closed

Handling archiveless posts in Elasticsearch queries #62

renatonascalves opened this issue Nov 3, 2023 · 0 comments · Fixed by #64
Assignees
Labels
elasticsearch Requires understanding Elasticsearch enhancement New feature or request php Requires understanding PHP

Comments

@renatonascalves
Copy link
Contributor

renatonascalves commented Nov 3, 2023

Description

This is a similar problem with #61. The only difference is that Elasticsearch performs the request.

I noticed that by toggling the "Hide from Archives" button, the post is completely removed from Elasticsearch. Not only hidden but literally gone.

That means one can index post types with support for the plugin but need to search (with Elasticsearch) it is impossible.

In other Alley projects (see alleyinteractive/byline-manager#120), that's been talks about handling it in the culprit plugin rather than leaving to consumers to resolve.


I was able to track the source of the issue to this line. That's then used here. That's being affected by these loc:

public function updated_post_meta( $meta_id, $object_id, $meta_key, $meta_value ) {
// Only handle updates to this plugin's meta key.
if ( self::$meta_key !== $meta_key ) {
return;
}
// If we are autosaving or the current post is a revision, bail.
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
|| wp_is_post_revision( $object_id )
|| wp_is_post_autosave( $object_id )
) {
return;
}
// Try to get the post object.
$post_object = get_post( $object_id );
if ( empty( $post_object->post_status ) ) {
return;
}
// Get the current status and switch if necessary.
$is_archiveless = 1 === (int) $meta_value;
if ( $is_archiveless && 'publish' === $post_object->post_status ) {
// Archiveless was requested, but the post's status is currently publish, so we need to change it.
$post_object->post_status = self::$status;
} elseif ( ! $is_archiveless && self::$status === $post_object->post_status ) {
// Archiveless was turned off, so we need to set the post status back to publish.
$post_object->post_status = 'publish';
} else {
// No change, so bail early.
return;
}
// Update the post with the new status.
wp_update_post( $post_object );

Use Case

This bug recently affected a client site. The client has a post type where they can't search the parent post in the Page Attributes slotfill because the archived parent doesn't appear in the results list (since it is removed from Elasticsearch).

The client uses VIP Search. But we should consider other plugins, like SearchPress, in the solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
elasticsearch Requires understanding Elasticsearch enhancement New feature or request php Requires understanding PHP
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant