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

The Feature Sync Is Looping #3976

Closed
1 task done
DarioBF opened this issue Sep 11, 2024 · 4 comments
Closed
1 task done

The Feature Sync Is Looping #3976

DarioBF opened this issue Sep 11, 2024 · 4 comments

Comments

@DarioBF
Copy link

DarioBF commented Sep 11, 2024

Describe your question

Hello,

We have just installed an ElasticSearch 8.15.1 instance, and the ElasticPress plugin is stuck in a loop during the initial sync. Is there a specific version of ElasticSearch required?

Best regards.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@burhandodhy
Copy link
Contributor

Hi @DarioBF,

The plugin works fine with Elasticsearch 8.12.2. Since 8.15.1 is not a major version, I believe the plugin should also work with it. To figure out the problem, can you please confirm if you are seeing any errors in the browser console?

Additionally, have you tried running the sync using the WP CLI command wp elasticpress sync --setup --yes --show-errors --force?

Regards,
Burhan

@DarioBF
Copy link
Author

DarioBF commented Sep 18, 2024

It seems that the CLI method worked.

Now, I have another problema trying to use the related posts query function:
$related_posts_query = \ElasticPress\Features::factory()
->get_registered_feature( 'related_posts' )
->get_related_query( $post_id, 5 );

This site has no posts, only custom post types contents... Is there any way to make that "get_related_query" and "find_related" search for current post type?

The documentation followed is not enough about that issue: https://www.elasticpress.io/documentation/article/related-posts-api/

@DarioBF
Copy link
Author

DarioBF commented Sep 19, 2024

Hi again,
maybe this is the way?

function modify_related_posts_query_args( $args ) {
	$post_id   = get_the_ID();
	$post_type = get_post_type( $post_id );

	$args['post_type'] = $post_type;
	return $args;
}
add_filter( 'ep_find_related_args', 'modify_related_posts_query_args' );

function abn_eloutput_related_posts( $content ) {
	if ( ! current_user_can( 'manage_options' ) ) {
		return $content;
	}
	if ( ! class_exists( '\ElasticPress\Features' ) ) {
		return $content;
	}

	$post_id = get_the_ID();

	$related_posts_query = \ElasticPress\Features::factory()
		->get_registered_feature( 'related_posts' )
		->get_related_query( $post_id, 5 );

	if ( $related_posts_query instanceof WP_Query ) {
		if ( $related_posts_query->have_posts() ) {
			while ( $related_posts_query->have_posts() ) {
				$related_posts_query->the_post();
				// echo '<a href="' . get_the_permalink() . '">' . get_the_title() . '</a><br>';
				var_dump( get_the_title() );
			}
			wp_reset_postdata();
		} else {
			echo 'No hay publicaciones relacionadas de ElasticPress.';
		}
	} else {
		echo 'La consulta no es una instancia de WP_Query';
	}

	return $content;
}
add_action( 'the_content', 'abn_eloutput_related_posts', 10 );

It's working, I think!

Is it the proper way to implement something like this?

Regards.

@felipeelia
Copy link
Member

Yes, it is, @DarioBF! Perhaps you should remove that first if inside abn_eloutput_related_posts, or related posts will not be displayed to regular users, only administrators. I'm going ahead and closing the issue now, but if you have any follow up questions, let us know. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants