WordPress.org

Ready to get started?Download WordPress

Forums

Attachments
[resolved] Cannot add custom fields (12 posts)

  1. apakin
    Member
    Posted 1 year ago #

    Hi!
    I've installed the plugin and edited the functions.php:

    function my_attachments( $attachments )
    {
      $args = array(
    
        // title of the meta box (string)
        'label'         => 'My Attachments',
    
        // all post types to utilize (string|array)
        'post_type'     => array( 'post', 'page' ),
    
        // allowed file type(s) (array) (image|video|text|audio|application)
        'filetype'      => null,  // no filetype limit
    
        // include a note within the meta box (string)
        'note'          => 'Attach files here!',
    
        // text for 'Attach' button (string)
        'button_text'   => __( 'Attach Files', 'attachments' ),
    
        // text for modal 'Attach' button (string)
        'modal_text'    => __( 'Attach', 'attachments' ),
    
        // fields for this instance (array)
        'fields'        => array(
          array(
            'name'  => 'title',                          // unique field name
            'type'  => 'text',                           // registered field type (field available in 3.0: text)
            'label' => __( 'Title', 'attachments' ),     // label to display
          ),
          array(
            'name'  => 'caption',                        // unique field name
            'type'  => 'text',                           // registered field type (field available in 3.0: text)
            'label' => __( 'Caption', 'attachments' ),   // label to display
          ),
          array(
            'name'  => 'group',                      // unique field name
            'type'  => 'text',                           // registered field type (field available in 3.0: text)
            'label' => __( 'Group', 'attachments' ), // label to display
          ),
        ),
    
      );
    
      $attachments->register( 'my_attachments', $args ); // unique instance name
    }

    But I still don't see the “Group” field in “Edit Post”: screenshot

    Thank you

    M

    http://wordpress.org/extend/plugins/attachments/

  2. Jonathan Christopher
    Member
    Plugin Author

    Posted 1 year ago #

    Hi M, you need to add the action as well:

    add_action( 'attachments_register', 'my_attachments' );

    You can add that below the function you pasted.

  3. Jonathan Christopher
    Member
    Plugin Author

    Posted 1 year ago #

    Also, your screenshot is using the default instance (meta box titled Attachments with two fields, one for Title one for Caption) -- if you don't want to use the default instance you can disable it and use the one you're defining in your snippet by adding the following to your wp-config.php:

    define( 'ATTACHMENTS_DEFAULT_INSTANCE', false );

  4. apakin
    Member
    Posted 1 year ago #

    I have this string. Sorry, didn't write it.

    $attachments->register( 'my_attachments', $args ); // unique instance name
    }
    
    add_action( 'attachments_register', 'my_attachments' );
  5. Jonathan Christopher
    Member
    Plugin Author

    Posted 1 year ago #

    Did you disable the default instance? Your snippet will work as expected, I tested locally and it works. Perhaps the meta box is hidden (check your Screen Options tab in the upper right of the post edit screen)?

  6. apakin
    Member
    Posted 1 year ago #

    Cannot disable right now, I don't have FTP access.
    But the irony is that it's worked till I upgraded the plugin.
    OK, thanx for help, I will wait for a man with FTP-password :)

  7. Jonathan Christopher
    Member
    Plugin Author

    Posted 1 year ago #

    Which version was it working with? Which version did you upgrade to that broke it?

  8. apakin
    Member
    Posted 1 year ago #

    From 1.6.2.1 to 3.0.6

  9. Jonathan Christopher
    Member
    Plugin Author

    Posted 1 year ago #

    I see, okay so yes I'm thinking you're actually working with the default instance instead of the one you're trying to register. Are there two meta boxes on the edit screen?

  10. apakin
    Member
    Posted 1 year ago #

    Sorry, but it still doesn't work.
    I don't even know where to look.

    Screenshot of Screen Options (I don't see “meta box” there).
    Screenshot of editor with functions.php (yes, I've pressed “Update File” button :))
    Screenshot of wp-config.php

    Attachments 3.0.6, WP 3.4.2

  11. apakin
    Member
    Posted 1 year ago #

    And another one thing: when I opened functions.php and wp-config.php, there wasn't this required blocks of code. How did it work before update? Could plugin update delete this strings? If not, I don't understand, how it was working. Till yesterday update another man configured WP with all the plugins :(

    Sorry for my terrible English and yammer, I'm in little panic :)

  12. Jonathan Christopher
    Member
    Plugin Author

    Posted 1 year ago #

    No, the plugin does not touch what you've written, it's worked the same way since 3.0 launched. These snippets were not part of 1.6 and earlier. If you can pass along WordPress login information to jonathan@mondaybynoon.com I'd be more than happy to figure out what's missing.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.