Skip to:
Content
Pages
Categories
Search
Top
Bottom

the Ajax Wire – – problem with loop


  • 4522774
    Inactive

    I’m trying to build a component which make wire ajax-ified. In the sense you can post something via Ajax, without reloading the page.

    I achieved to save message in background.

    think same think would be to delete it.

    But I have a prob…I’m not able to make bp return me the “graphic” instance of the just saved wire post.

    have you some ideas on how to achieve that???

    This is my code used to save the wire:

    function bp_wire_ajax_save_post(){ //todo: set return value

    global $bp;

    //print_r($bp);

    if (is_user_logged_in()){

    $message = $_POST['wire-post-textarea'];

    if($message=='')

    $message='ciaoooooo';

    //save the message

    $postId = bp_wire_new_post($bp->loggedin_user->id, $message, $bp->profile->slug, false, $bp->profile->table_name_wire);

    $args = 'item_id=' . bp_wire_item_id() . '&can_post=' . bp_wire_can_post() ;

    echo $args;

    }

    It work like a charm. Please don’t see some “echo” etc, they are debug info. This is not the final version :P

    Now the difficult one: I use this to retrieve the graphic wire instance from template, but the loop doesn’t work…

    $args ='item_id=' . $_POST['bp_wire_item_id'] . '&can_post=1';

    $args = 'item_id='.$bp->loggedin_user->id.'&component_slug='.$bp->current_component.'&max=1&per_page=1&can_post=' . bp_profile_wire_can_post() ;

    $args = 'item_id=' . bp_wire_item_id() . '&can_post=' . bp_wire_can_post() ;

    echo $args;

    <?php if ( bp_has_wire_posts( $args ) ) : ?>

    //print wire

    but it show me always “no wire to post”

    someone could help me???

    additional information:

    this functions are in the “backend” file, so when i call this I’m not on the “buddypress plugin registered core”…

    I can save wire because I import these in my backend file:

    require_once ( $_SERVER["DOCUMENT_ROOT"] . '/social/site/wp-config.php');

    require_once ( ABSPATH . WPINC . '/pluggable.php');

    require_once ( BP_PLUGIN_DIR . '/bp-core.php');

    global $bp;

    bp_core_setup_globals();

    Maybe I’m forgotting something?

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

  • 4522774
    Inactive

    up?


    Andy Peatling
    Keymaster

    @apeatling

    I’m not sure you are approaching this correctly. Use the existing AJAX functions as a guideline. You should not need to include the WP environment if you are using the wp_ajax_ hook.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘the Ajax Wire – – problem with loop’ is closed to new replies.
Skip to toolbar