BuddyDev

Search

[Resolved] BuddyBlog Pro – Custom field types

  • Participant
    Level: Master
    Posts: 279
    NikB on #46181

    Hi again Brajesh

    I’m hoping to be able to use BuddyBlog Pro to allow users to add their own Events (custom post type) but although I see there is a Date field type, there is no Time field type which is pretty much essential for most events (ie. start and finish times).

    How difficult would it be to add an additional field type to handle this?

    With thanks as always
    Nik

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #46183

    Hi Nik,
    Will a time field like this work?
    https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/time

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 279
    NikB on #46185

    Hi Brajesh

    Thank you and that certainly looks promising.

    Although actually I’ve just checked the postmeta for the events plugin I’m currently testing and unfortunately it seems to store the start date/time in the same field in the format “2022-08-31 08:00:00” that said… perhaps there is some way I could combine a BuddyBlog Pro date field along with a time field prior to saving, in order to produce the relevant string for the meta?

    Regards
    Nik

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #46204

    Hi Nik,
    Thank you.
    We will add a date/time field to solve this issue. It will need a little time. I will update you in couple of days with the timeline.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 279
    NikB on #46208

    Hi Brajesh

    Many thanks for considering this. Although not ideal, I guess I MAY be able to get around it temporarily by using text fields and instructing the users to use a particular format when entering their date/time (and just hope the users actually read and follow the instructions) but if/when you have time, a date/time field would definitely be useful and very much appreciated.

    Regards
    Nik

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #46226

    Thank you Nik.
    I appreciate it.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 279
    NikB on #46267

    Hi Brajesh

    Just wanted to add that having just discovered the ‘bblpro_post_submission_prepared_data’ filter, it looks as if it would be relatively easy for me to combine a time field (such as that which you suggested above) with the existing date field in order to save the postmeta in a suitable format for my events plugin.

    In other words, if implementing the above time field would be a relatively “quick fix” as compared to implementing a full date/time field, that would certainly be perfectly acceptable for my purposes at this stage… and if it’s something I can implement myself (with a little guidance from you) even better…

    No worries if not though… the groups functionality is far more of a priority for me at least and hope that’s all going well.

    Regards
    Nik

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #46285

    Hi Nik,
    Thank you.

    We will be able to look at it after the release of the BuddyBlog Groups adodn.

    If you want to create a field yourself, Please take a look at our implementation in buddyblog-pro/core/fields.

    You can create a cusotm field type and register them using the filter ‘bblpro_registered_field_type_classes’

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 279
    NikB on #46287

    Thank you so much Brajesh. That’s exactly the kind of info I needed… I’ll take a look.

    Regards
    Nik

  • Participant
    Level: Master
    Posts: 279
    NikB on #46293

    Hi Brajesh

    I’ve made a start on attempting to update my Event custom post type postmeta by creating a custom field (my_date) on the relevant form and then using the code below but for some reason, it doesn’t seem to be picking up a value for $_POST[‘my_date’].

    This doesn’t seem to be anything to do with the field type as I’ve tried changing it to a text field and that doesn’t seem to make any difference. Indeed, if I run the same code but using $_POST[‘bbl_post_title’] then everything works fine (even if it doesn’t make much sense!) so this seems to be an issue with custom fields only…

    Could it be something to do with the fact taht the field name actually seems to appear as “bbl_custom_field[my_date]” (ie. including square brackets in the name itself) so possibly I need to reference it slightly differently?

    Here’s the code I’ve tried so far…

    ` add_filter( ‘bblpro_post_submission_prepared_data’, function ( $post_data, $form_id, $post, $is_submission ) {

    if ( 2487 === (int) $form_id ) {

    $mydate = $_POST[‘my_date’] . ‘ 11:00:00’;
    //$mydate = $_POST[‘bbl_custom_field[my_date]’] . ‘ 11:00:00’;

    if ( ! empty( $post_data[‘ID’] ) ) {
    update_post_meta( $post_data[‘ID’], ‘_EventStartDate’, $mydate);

    }
    }

    return $post_data;
    }, 10, 4 ); `

    With many thanks in advance for any thoughts.
    Nik

The topic ‘ [Resolved] BuddyBlog Pro – Custom field types’ is closed to new replies.

This topic is: resolved