-
-
Save tommcfarlin/13ff8610716de3cb5b5e612d80267e9e to your computer and use it in GitHub Desktop.
[WordPress] On Writing Clever Code with Arrays in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Get the excerpt from the incoming post. | |
$post = get_post( $post_id ); | |
$excerpt = $post->post_excerpt; | |
/** | |
* And we update the post content without the information (and we don't need | |
* paragraph tags). | |
*/ | |
$event_post->post_excerpt = | |
apply_filters( | |
'the_excerpt', | |
implode( ', ', | |
array_diff( | |
array_map( | |
'trim', | |
explode( ',', $excerpt ) | |
), | |
array( $name ) ), | |
), | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Get the excerpt from the incoming post. | |
$post = get_post( $post_id ); | |
$excerpt = $post->post_excerpt; | |
// Remove the name from the array of names in the excerpt. | |
$to_remove = array( $name ); | |
$names = array_map( 'trim', explode( ',', $excerpt ) ); | |
$result = array_diff( $names, $to_remove ); | |
// Now creae the new excerpt. | |
$new_excerpt = implode( ', ', $result ); | |
/** | |
* And we update the post content without the information (and we don't need | |
* paragraph tags). | |
*/ | |
$event_post->post_excerpt = apply_filters( 'the_excerpt', $new_excerpt ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment