WordPress.org

Ready to get started?Download WordPress

Forums

WP to Twitter
[resolved] Custom meta? (15 posts)

  1. iulianba
    Member
    Posted 11 months ago #

    Hello,

    I was wondering if your plugin offer support for custom post meta. I have some data that will be nice to tweet. I only see custom-post-types support.

    Regards,
    Julian

    http://wordpress.org/extend/plugins/wp-to-twitter/

  2. Joe Dolson
    Member
    Plugin Author

    Posted 11 months ago #

    Yes, it does.you can access custom meta using custom template tags in the format [[custom-field-name]]

  3. iulianba
    Member
    Posted 11 months ago #

    Thanks for answering. My question was not how can I use custom-field-name. I have a serialized custom post meta for each article. Is there any support for adding custom code?

  4. Joe Dolson
    Member
    Plugin Author

    Posted 11 months ago #

    I'm not sure what you mean. Do you mean a filter? There are a number of filter hooks in WP to Twitter that you can use to customize various elements of the output.

  5. iulianba
    Member
    Posted 11 months ago #

    I dont know how to explain it. But here its what I do know :)

    In wp_postmeta, for each post I have a meta key that contains some meta values that are serialized.
    Example: for a product, i have:
    a:7:{s:11:"price";s:4:"Free";s:17:"author";s:42:"James";}

    I would like to use values from here on the tweet. Is there any way?

    Thanks

  6. Joe Dolson
    Member
    Plugin Author

    Posted 11 months ago #

    Not at the moment, no. But I'll consider that. Simple custom fields are easily incorporated, but there isn't currently a means to access serialized data from custom fields.

  7. Joe Dolson
    Member
    Plugin Author

    Posted 11 months ago #

    Next release will have a filter to make use of custom fields.

    Basic usage:

    add_filter( 'wpt_custom_shortcode', 'filter_shortcode', 10, 3 );
    function filter_shortcode( $value, $post_ID, $field ) {
    	$value = get_post_meta( $post_ID, $field );
    	$value = implode( ", ",$value );
    	return $value;
    }

    Next release should go out very soon.

  8. iulianba
    Member
    Posted 11 months ago #

    Thank you!

    I`m looking forward to this.

  9. Joe Dolson
    Member
    Plugin Author

    Posted 11 months ago #

    The new version is now available.

  10. iulianba
    Member
    Posted 11 months ago #

    Thanks for letting me now. I don`t know how to use this. Is there any code sample out there?

  11. Joe Dolson
    Member
    Plugin Author

    Posted 11 months ago #

    Yes - as I provided above. Also, read the WordPress codex entry on filters: http://codex.wordpress.org/Function_Reference/add_filter

  12. iulianba
    Member
    Posted 11 months ago #

    Sorry, but I don`t get this.
    I made this:

    add_filter( 'wpt_custom_shortcode', 'filter_shortcode', 10, 3 );
    function filter_shortcode( $value, $post_ID, $field )
    {
        $value = maybe_unserialize(get_post_meta($post_ID, $field,true));
        $value = implode( ", ",$value );
        return $value;
    }

    Now what? How do I take specific fields from the post meta and use them with your plugin? I see to use double brackets. Something like filter_shortcode? Then how do i specify what do i want to get?...

    Regards

  13. Joe Dolson
    Member
    Plugin Author

    Posted 11 months ago #

    If you have a custom field called, for example, "my-custom-field", then you use a template tag [[my-custom-field]].

    The field name goes through the filter as the 3rd argument ( $field, in the example function).

    What the filter does is instead of using the default output from the double square bracketed custom template tag, it replaces them with the content as you choose to format it in your custom function.

  14. iulianba
    Member
    Posted 11 months ago #

    I`m not sure, but we might talk about something different.
    I have this custom post meta key in wp_postmeta.
    So for each post I need a couple of the serialized data.
    For example, when I update a post, I want to take from that the price and author. Or app version, or whatever. I don`t need only one thing.
    Here`s the structure: http://hcd-1.imgbox.com/abqMVr0o.jpg?st=EbsO0Phl8B62nnzFkmR6eg&e=1369775029

    So I don`t really get how can I use what you just said. Because if I put the code in the brackets, how do I set multiple values? For example, for price and another one for author.

    Regards

  15. Joe Dolson
    Member
    Plugin Author

    Posted 10 months ago #

    You just need to use the shortcode to extract those fields - I can't teach you PHP; but it's just a matter of unserializing the data, extracting and formatting the fields you want, then returning it to the tag:

    function filter_shortcode( $value, $post_ID, $field )
    {
    $value = maybe_unserialize(get_post_meta($post_ID, $field,true));
    $string = $value->author .' '.$value->price;
    return $string;
    }

    That would assume your serialized data is a serialized object, but it would get the information.

Reply

You must log in to post.

About this Plugin

About this Topic