WordPress.org

Ready to get started?Download WordPress

Forums

Pods - Custom Content Types and Fields
[resolved] Adding post from frontend with related fields (2 posts)

  1. dituyi
    Member
    Posted 10 months ago #

    Hello,

    i'm stuck and i need your help, please.

    I have this scenario:
    - Advanced Content Type called "ciudades". Inside, 2 fields: "ciudad" and "provincia".
    - Custom Post Type called "anuncios". There are some fields, but i'll focus on two fields: "provincia" and "ciudad" (related to the pod "ciudades" and its fields)
    - I have a custom form to add a new post into "anuncios" passing data through $_POST. There are some text fields in it, a simple select field (for "provincia"'s items) and a checkbox field (for "ciudad"'s items).

    The post is created and text areas are added successfully but nothing works with select field and checkbox although their values are being passed right through $_POST because i can do an echo of them.

    This is the code i'm using to add the fields into the new post:

    $fields= array(
    'post_title' => $nombre,
    'post_content' => $contenido,
    'post_author' => $autor,
    'provincia.provincia' => $provincia,
    'ciudad.ciudad' => $ciudad
    );

    $new_id = $anuncios->add($fields);

    What code should i use to achieve that?

    Thank you very much!

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

  2. Scott Kingsley Clark
    Member
    Plugin Author

    Posted 9 months ago #

    You can't add new items for relationship fields (yet) within add/save, but you can set IDs for those items.

    Try this:

    $fields= array(
        'post_title' => $nombre,
        'post_content' => $contenido,
        'post_author' => $autor,
        'provincia' => $provincia, // should be an ID, or an array of IDs
        'ciudad' => $ciudad // should be an ID, or an array of IDs
    );
    
    $new_id = $anuncios->add($fields);

Reply

You must log in to post.

About this Plugin

About this Topic