Created
October 16, 2015 03:41
-
-
Save Aziz-Rahman/1b5f0833d73978cd545a to your computer and use it in GitHub Desktop.
Check if exists value in wp
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
$args = array( | |
'post_type' => 'post', | |
'meta_query' => array( | |
array( | |
'key' => 'post_url', // custom post type | |
'value' => $the_url_topic // value yg diinputkan | |
) | |
), | |
'fields' => 'ids' // id from wp | |
); | |
// perform the query | |
$url_query = new WP_Query( $args ); | |
$query_url_ids = $url_query->posts; | |
if ( ! empty( $query_url_ids ) ) { | |
echo '<p class="warning-msg"><i class="icon icon-warning"></i> '; | |
_e( 'Your url topic is exists !, please re-enter your url.', 'text_domain' ); | |
_e( 'The same post with the url above : ', 'text_domain' ); | |
$url_ids = $query_url_ids[0]; | |
echo '<a href="'.get_permalink( $url_ids ).'">'.get_permalink( $url_ids ).'</a>'; | |
echo '</p>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment