Created
April 21, 2021 21:05
-
-
Save Garconis/8383b998c945b97529930d3c3918028a to your computer and use it in GitHub Desktop.
WP All Import | Update list of posts by matching post slug via Record Matching
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 | |
// https://wordpress.org/support/topic/bulk-edit-record-matching-by-slug/#post-14026355 | |
// Create custom PHP function that we can use in the "Post ID" field under Record Matching | |
// We pass the post slug to our function, then we use this function tot look up the post by its slug, to return the Post ID | |
function fs_get_post_by_slug( $slug, $post_type = 'post' ) { | |
if ( $post = get_page_by_path( $slug, OBJECT, $post_type ) ) { | |
return $post->ID; | |
} | |
} | |
/** | |
Usage in the "Post ID" field would be: | |
[fs_get_post_by_slug({postslug[1]})] | |
... {postslug[1]} should be changed to whatever the slug's column name (node/tag) is from the CSV you're using, such as {slug[1]} | |
If matching a custom post type, then pass the post type slug as the second parameter, to override the function's default of post: | |
[fs_get_post_by_slug({postslug[1]},"product")] | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment