• I have a Custom Post Type ‘services’ on my wordpress site with a number of custom fields that I can access via

    require_once('../wp-blog-header.php');
    
    query_posts(array( 
            'post_type' => 'service',
            'showposts' => 10000 
        ) );  
    
    print "<table>";
    print "<tr style=\"font-weight:bold;\"><td>Name</td><td>Link to entry on map</td><td>Overview</td><td>Address 1</td><td>Address 2</td><td>Address 3</td><td>Address 4</td><td>Address 5</td><td>Town/city</td><td>Postcode</td><td>Telephone</td><td>Email address</td><td>Website</td><td>Contact name</td><td>Facebook</td><td>Twitter</td><td>Youtube</td><td>Management</td><td>Referral</td><td>Local authority</td><td>Type of Service</td></tr>\n";
    while (have_posts()) : the_post(); 
    	$overview = get_post_meta( get_the_ID(), 'overview_meta_box_text', true ); 
    $address = get_post_meta( get_the_ID(), 'address_meta_box_text', true );
        $address2 = get_post_meta( get_the_ID(), 'address2_meta_box_text', true );
        $address3 = get_post_meta( get_the_ID(), 'address3_meta_box_text', true );
        $address4 = get_post_meta( get_the_ID(), 'address4_meta_box_text', true );
        $address5 = get_post_meta( get_the_ID(), 'address5_meta_box_text', true );
        $city = get_post_meta( get_the_ID(), 'city_meta_box_text', true );
        $postcode = get_post_meta( get_the_ID(), 'postcode_meta_box_text', true );
        $telephone = get_post_meta( get_the_ID(), 'telephone_meta_box_text', true );
        $email = get_post_meta( get_the_ID(), 'email_meta_box_text', true );
        $web = get_post_meta( get_the_ID(), 'web_meta_box_text', true );
        $web = str_replace("http://","",$web);
        $contact = get_post_meta( get_the_ID(), 'contact_meta_box_text', true );
        $facebook = get_post_meta( get_the_ID(), 'facebook_meta_box_text', true );
        $twitter = get_post_meta( get_the_ID(), 'twitter_meta_box_text', true );
        $youtube = get_post_meta( get_the_ID(), 'youtube_meta_box_text', true );
        $management = get_post_meta( get_the_ID(), 'management_meta_box_text', true );
        $referral = get_post_meta( get_the_ID(), 'referral_meta_box_text', true );

    How can I add another field which would be a integer?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • How did you create this custom post type? Is this built into your theme, or part of a plugin?

    There are a few ways to do what you’re asking – including using Advanced Custom Fields, adding more fields to your post type’s metabox, etc.

    Thread Starter gdouglas74

    (@gdouglas74)

    We got an external developer (that we are unable to contact) to create for us. I don’t think it’s a plugin (as there are no plugin installed that it could be) I tried Advanced Custom Fields but it just displayed ‘No Field Groups found’

    Moderator bcworkz

    (@bcworkz)

    It sounds like custom code and files simply added to your theme.

    You could add your own values for a new field by using the default custom field meta box on the post edit screen. Then retrieve it by whatever field name you used with something like get_post_meta( get_the_ID(), 'whatever_field_name', true );

    If the value returned is assigned to a variable like the others, it can then be output where you want on the code page much like the other values. Whether it’s an integer or a string makes little difference in PHP. The new field could alternatively be added to the current custom meta box just like all the other fields, using the existing code as an example. Since we don’t know what that looks like, there’s little we can say about it.

    If such code alterations are beyond your skills, you’ll be better off hiring a professional. One resource for finding such developers is jobs.wordpress.net . If adding a single field is all you need it shouldn’t be very expensive.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Add custom fields to a custom post type’ is closed to new replies.