Get all postal IDs in Wordpress

Is it possible to get an array of all mail identifiers currently available in Wordpress DB (regardless of post_types)? Also, is it possible to get an array of all postal identifiers of a particular post_type type?

If possible, how to do this?

+6
source share
2 answers

You can try this way

$post_ids = get_posts(array( $args, //Your arguments 'posts_per_page'=> -1, 'fields' => 'ids', // Only get post IDs )); 
+6
source

it is probably best to run a custom query using a wordpress DB object. (from functions.php file or theme file, etc.):

  // pseudo-code check how to refer to the field columns and table name! global $wpdb; $sql="SELECT id, title FROM posts"; $posts = $wpdb->get_results($sql); print("<ul>"); foreach ($posts as $post) { print('<li>'.$post->FIELD1.'|'.$post->FIELD2.'<br/>'); print('</li>'); } print("</ul>"); 

I think that in fact you can get this also with the standard wp_query object .... but at least my way is to first execute the request in phpmyadmin and then configure the / wordpress syntax prefix. (read the code on the database object). If it is one-time, just use phpmyadmin, but for programmatic use you have to convert it to run from the functions.php file.

+3
source

Source: https://habr.com/ru/post/922745/


All Articles