Forums

Ajax solution similar to WP Categories functioning in Admin area (6 posts)

  1. dashaluna
    Member
    Posted 1 year ago #

    Hello everyone,

    I'd like to implement the same functionality as WP Categories screen in the Admin area. Where you can add category and it will appear in the list of all categories straight away.

    I have a CD custom post type and I would like to add tracks to a CD in the same way as WP Categories are added (Hope that makes sense).

    I'm a novice and unfortunately can't figure it out myself. I would really appreciate if people could point me to some tutorial / anything that explain ajax in WP with examples.

    Many thanks.

  2. Mohammad Jangda
    Member
    Posted 1 year ago #

    If a track can only be on 1 CD at a time, you might be better off registering Tracks as a custom post types and then use the Post2Posts plugin to connect them.

    If want to go the "category" route, you can register Tracks as a taxonomy and WordPress will generate the necessary metaboxes for you.

  3. Matthew Muro
    Member
    Posted 1 year ago #

    Here's a pretty in-depth answer on Adding a Taxonomy Filter to the Admin which should get you pointed in the right direction.

  4. dashaluna
    Member
    Posted 1 year ago #

    @Mohammad Jangda, thanks a lot with the tips.

    I think registering Tracks as a taxonomy isn't ideal solution. I wanted "category management functionality" to be within a screen for a CD, to make it intuitive for a user.

    I'll have a look at the plugin :)

    Thanks a lot!

  5. sdh100Shaun
    Member
    Posted 1 year ago #

    I did a similiar thing in a plugin prior to 3.0 i.e. not with custom post types but as your tag suggests used ajax

    I used jQuery with a ajax request like this
    $.post(url, { action:"uon_post","cookie": encodeURIComponent(document.cookie),postId: $('#post_ID').val() ,"storytype":storytype,"ImgPath":imgPath },

    and the recieving plugin function /action like this

    add_action('wp_ajax_uon_post', 'postManagementajaxCall');
    function postManagementajaxCall()
    	{
    
    		$return="";
    
    		if(isset($_POST))
    		{
    			$filters = array
    		  (
    		  "postId" => FILTER_VALIDATE_INT,
    		  "storytype" => FILTER_SANITIZE_STRING,
    		  "ImgPath"=> FILTER_SANITIZE_STRING
    		  );
    
    			$args=filter_var_array($_POST, $filters);
    
    			global $wpdb; 
    
    			$postManagement= new PostManagement($wpdb);
    
    			echo $postManagement->processPost($args["postId"],$args["storytype"],$args["ImgPath"]); 
    
    			exit();
    		}
    	}

    The key things to note are the action name in both the jquery/javascript and php

    Hope that helps along the way a bit - feel free to ask for clarification (happy to help if I can) @sdh100shaun

  6. dashaluna
    Member
    Posted 1 year ago #

    @sdh100Shaun, thanks for your reply. I think I need something similar, the problem that I don't understand very well what the code does, so still looking for a good tutorial that would explain it.

    I've also posted this question on another forum:
    http://wordpress.stackexchange.com/questions/3570/ajax-solution-similar-to-wp-categories-functioning-in-admin-area

    I was given a good general directions, but stuck with adding AJAX form to a meta box in a custom post type edit screen... The first problem that I'm having is that I can't have a form (for adding my track) within another form (the main post form). So I don't know how to go on with this :(

    Would really appreciate if someone could help me out. Please have a look at the answer and comments for this post http://wordpress.stackexchange.com/questions/3570/ajax-solution-similar-to-wp-categories-functioning-in-admin-area

    Many thanks,
    Dasha

Topic Closed

This topic has been closed to new replies.

About this Topic