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

Implicit excerpt from content should be an option and not mandatory #1314

Open
henrikwirth opened this issue May 18, 2020 · 8 comments
Open
Labels
Status: Discussion Requires a discussion to proceed Type: Feature

Comments

@henrikwirth
Copy link
Collaborator

henrikwirth commented May 18, 2020

When querying for an excerpt in a post and the post has not explicitly defined an excerpt, at the moment, the excerpt gets created from the content.

That's a problem, because if in the frontend, I want to only show an excerpt if it is defined, I can't. It will always contain content with the current implementation.

Three options, how it could be handled come into my mind:

  1. There is a flag, like excerptExists.
  2. There is a format option like excerpt(format: "fromContent") or something similar. Default should be null if not defined.
  3. There are 2 fields: excerpt and excerptContent or contentExcerpt

I personally lean to option 3 or 2.

@jasonbahl jasonbahl added this to the 1.0 release milestone Jun 30, 2020
@jasonbahl jasonbahl removed this from the 1.0 release milestone Aug 4, 2020
@drewbaker
Copy link

I'd vote option 2 as the one that makes the most sense, but not sure how that would work with excerpt(format: RAW) would you need excerpt(format: RAW_FROM_CONTENT)?

@stale
Copy link

stale bot commented Aug 3, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 3, 2022
@stale
Copy link

stale bot commented Sep 2, 2022

This issue has been automatically closed because it has not had recent activity. If you believe this issue is still valid, please open a new issue and mark this as a related issue.

@stale stale bot closed this as completed Sep 2, 2022
@justlevine justlevine reopened this Sep 2, 2022
@stale stale bot removed the stale label Sep 2, 2022
@stale
Copy link

stale bot commented Dec 1, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale? May need to be revalidated due to prolonged inactivity label Dec 1, 2022
@stale
Copy link

stale bot commented Mar 1, 2023

This issue has been automatically closed because it has not had recent activity. If you believe this issue is still valid, please open a new issue and mark this as a related issue.

@stale stale bot closed this as completed Mar 1, 2023
@justlevine justlevine reopened this Mar 1, 2023
@justlevine justlevine added Status: Discussion Requires a discussion to proceed and removed Stale? May need to be revalidated due to prolonged inactivity labels Mar 3, 2023
@drewbaker
Copy link

Just ran into this today again... would love a way to only get excerpts if they were actually entered into the field, not falling back to auto generated ones.

@drewbaker
Copy link

Temp solution is to put this in your functions.php file:

/**
 * Give each excerpt node a field of the user defined excerpt, or empty string.
 * SEE https://github.com/wp-graphql/wp-graphql/issues/1314
 */
function add_defined_excerpt_field() {
	register_graphql_field(
		'NodeWithExcerpt',
		'definedExcerpt',
		array(
			'type'    => 'String',
			'resolve' => function ( $post ) {
				// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
                $excerpt = '';
                if (has_excerpt()) {
                    $excerpt = wp_strip_all_tags( get_the_excerpt() );
                }
                return $excerpt;
			},
		)
	);
}
add_action( 'graphql_register_types', 'add_defined_excerpt_field' );

Which allows for something like this:
Screenshot 2023-08-31 at 9 39 12 AM

@mehov
Copy link

mehov commented Oct 19, 2023

Came here to post exactly this idea and found this existing issue.

I think there should be a way to either disable automatic excerpts, or have a flag so that I can easily decide in code on whether to render the excerpt I got.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Discussion Requires a discussion to proceed Type: Feature
Projects
Status: 🗺 Planned
Development

No branches or pull requests

5 participants