0
votes

I am working on this WordPress demo plugin where I want to display/show custom fields for each of these 3 post types (Post, Page, Custom Post Types). No matter how many of them there are.

Let me kind of illustrate the process further as much as I can.

  1. Post Post Type:
    1.1 All the Custom Fields of the posts

  2. Page Post Type:
    2.1 All the Custom Fields of the pages

  3. Custom Post Type:
    3.1 All the Customs Fields of the Custom Post Types individually (slug)

I am searching for built-in or Customized solution.

Thank you! Any direction is highly appreciated.

1

1 Answers

0
votes

Finally figured it out with little directions.

Here is how i achieved it.

global $namespace_get_options; // replace with your assigned get_options variable.

// Get all post types

$post_args = array(

    'public' => true, // only get publicly accessible post types

    '_builtin' => false, // remove builtin post types

);

// generate post type list

$post_types_for_rest = get_post_types($post_args, 'names');

// add built-in 'post and page' post type

$post_types_for_rest['post'] = 'post';

$post_types_for_rest['page'] = 'page';

foreach ($post_types_for_rest as $post_type_for_rest) {

    $args = array(

        'post_type' => $post_type_for_rest,

        'posts_per_page' => -1,

    );

    $the_query = new WP_Query($args);

    $posts = $the_query->posts;

    foreach ($posts as $post) {

        $post_id = $post->ID;

        $custom_field_keys = get_post_custom_keys($post_id);