I want to create some custom fields that will be able to show to a default wordpress post. I don't want to use the ACF plugin. Is there anyway to do it programmatically?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.Sign up to join this community
You can use the custom fields included in wordpress
Add a new post and do the following steps:
1. Go to the Options page
2. Select "custom fields" and hit the reload button
3. you now have a custom field in your post edit page at the bottom.
now you can use this custom field in your theme inside the
<?php while ( have_posts() ) : the post(); ?> <?php echo get_post_meta($post->ID, 'featured', true); ?> <?php endwhile; ?>
You have to replace 'featured' with the name of your custom field.
Once you created a custom field, you can use it in your others post as well.
Hope this is helpful.
This article walks you through creating a very basic, lightweight plugin to add your own meta fields. I'm sure it could be adapted to be used as a standalone function rather than a plugin.
Essentially you add your fields using
add_meta_box() and setting the post type to
post or whatever CPT you like. Update the fields using
update_post_meta(). Then display wherever you like using