Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[WordPress] On Writing Clever Code with Arrays in WordPress
<?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 ) ),
),
);
<?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
You can’t perform that action at this time.