Skip to content

Instantly share code, notes, and snippets.

@Aziz-Rahman
Created October 16, 2015 03:41
Show Gist options
  • Save Aziz-Rahman/1b5f0833d73978cd545a to your computer and use it in GitHub Desktop.
Save Aziz-Rahman/1b5f0833d73978cd545a to your computer and use it in GitHub Desktop.
Check if exists value in wp
$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