I want to create a custom post type for store that having all store names and it is working. Now I want to fetch the all stores in a select box in every new post of WordPress, then selected store name will used as custom field for that post. I want to save this store name as meta value for this post in wp_postmeta
table.
Every custom post having the post_type=’store’ so how I write a function to fetch all post by store type.
To get the posts from a post type you can use
get_posts()
Be aware, the
-1
is dangerous: If there are millions of stores, the query might run into a time-out.Here is a very basic example for such a meta box. You will find much more examples and explanations in our tag metabox.
To list all these associated posts in a store page, use a function that queries for post meta fields:
You could use this function as a shortcode handler:
Then just add
[storeposts]
wherever you need that list in your store.