WordPress.org

Support

Support » Plugins and Hacks » [Plugin: WP User Frontend] Custom Taxonomies

[Plugin: WP User Frontend] Custom Taxonomies

  • Hi Tareq I need help, regarding the custom fields I’ve solved the problem by changing the prefix of the custom field.
    But now I want to integrate custom taxonomies, my custom taxonomies already are created from the function.php of templae and are read from the same template and print. How can I do to insert a field input for custom taxonomies in-form? I can get a good donation or if you want you tell me how much it costs! thank you!

Viewing 15 replies - 1 through 15 (of 35 total)
  • Hi!

    I was about to ask the same (I guess..)…

    I am using this to output the new article form for a custom post type[wpuf_addpost post_type=”listing”] but it grabs the default categories only and is not listing my ‘listing_category’…

    How ca I do this?

    Thanks!

    Hi Rolf, this is the loop for the post type:

    $args = array( 'post_type' => 'listing', 'posts_per_page' => 10 );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    	the_title();
    	echo '<div class="entry-content">';
    	the_content();
    	echo '</div>';
    endwhile;

    (But your is an a different question)

    Thanks for share that piece of code but I was thinking that you want t integrate custom tax along whit this shortcode [wpuf_addpost post_type=”listing”]…

    I don’t understand your problem… (I do not speak English very well)
    (listing is not a category)

    Thanks for trying help-me!

    “listing” in my wordpress installation is a custom post type and I want to display custom categories from that custom post type when I use this shortcode: [wpuf_addpost post_type=”listing”]

    My custom taxonomies are “listing_category”.

    When I use [wpuf_addpost post_type=”listing”], the only categories listed on a dropdown box are the default categories from wordpress…

    ok, you can create a custom template for this! as
    listing-category.php
    the code:

    <?php
    /*
    Template Name: Listing Category
    */
    ?>
    <?php get_header(); ?>
    $args = array( 'post_type' => 'listing', 'cat=3', 'posts_per_page' => 10 );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    	the_title();
    	echo '<div class="entry-content">';
    	the_content();
    	echo '</div>';
    endwhile;
    <?php get_footer(); ?>

    ‘cat=3’, is the category number to display.

    Hi lorenzoporretti!

    Thanks, man! But what I need is a way to the plugin call the categories for custom post_types instead of calling the default wordpress categories.

    My problem is:

    I have a custom post_type with custom categories

    eg: listing is a custom post-type that haves a main category which is products…

    When I place this code [wpuf_addpost post_type=”listing”] on a page to those entries listed on the custom post_type “listing”, the plugin only calls the categories from my blog and not the categories of this custom post_type…

    Do know if there is a way to do it?

    Thanks!

    Hi,

    Any news on this? I’m desperate trying to get my custom taxonomies working :-/

    Thank you

    I have no news on this… sorry! Also posted this thread but got no replies…

    I find this:
    http://tareq.wedevs.com/2012/04/how-to-extend-wp-user-frontend/ (the author of plugin)
    and this:
    http://shibashake.com/wordpress-theme/add-term-or-taxonomy-meta-data
    … but I was not able to understand much about …

    J Grandin

    @j-grandin

    Dear all,

    I harshly found a solution to edit custom taxonomies panel in front end pages using WP User Frontend.

    Please check link above posted by lorenzo to see plugin extensions functions kindly suggested by Tareq, and look at the chapter ‘Processing the input’. The problem came when processing the data. Tareq example uses update_post_meta() but it only work for custom fields, not for custom taxonomies, that use wp_set_object_terms(). So you need to use this last function to save custom taxonomies in your front end form.

    First, create in functions.php your custom taxonomy input panel in a new function named for example wpufe_taxonomy(). I recommend this tutorial: WordPress Custom Taxonomy Input Panels by ShibaShake .
    Don’t use metaboxes functions & CSS as they only work in back end of course. Call your input panel in the front end add/edit page using Tareq extension functions.

    Then to save the data, you have to write this
    add_action('save_post', 'save_taxonomy_data');
    then create a save_taxonomy_data() function like suggested in the above tutorial.

    Example of a saving function for a select list of custom taxonomy items:

    if (function_exists('wpufe_taxonomy')) {
        add_action('save_post', 'save_taxonomy_data');
    }
    
    function save_taxonomy_data($post_id) {
    // verify this came from our screen and with proper authorization.
    
     	if ( !wp_verify_nonce( $_POST['taxonomy_noncename'], __FILE__ )) {
        	return $post_id; }
    
      	// verify if this is an auto save routine. If it is our form has not been submitted, so we dont want to do anything
      	if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
        	return $post_id;
    
      	// Check permissions
      	if ( 'post' == $_POST['post_type'] ) {
        	if ( !current_user_can( 'edit_page', $post_id ) )
          		return $post_id;
      	} else {
        	if ( !current_user_can( 'edit_post', $post_id ) )
          	return $post_id;
      	}
    
      	// OK, we're authenticated: we need to find and save the data
            $post = get_post($post_id);
    	if ($post->post_type == 'post') {
               $select_name = $_POST['select_name'];
    	   wp_set_object_terms( $post_id, $select_name, 'taxonomy_name' );
            }
    }

    Important note: using the following saving function suggested by Tareq will not work for some reason I can’t figure.

    function wpufe_add_taxonomy() {
        add_action('save_post', 'save_taxonomy_data');
    }
    add_action( 'wpuf_add_post_after_insert', 'wpufe_add_taxonomy' );

    Finally don’t forget to change select_name by the name attribute of your select list, in order to allow data processing.

    Again thanks Tareq for your fantastic work on this plugin.

    gerencia@enjambregroup.com

    @gerenciaenjambregroupcom

    Hi J Grandin, im a little confuse with all this i have a taxonomy created with Taxonomy Manager (plugin), the only thing that i need is how to add the select to the add / edit post and how to save it, could you give me a hand with this?

    J Grandin

    @j-grandin

    Dear Gerencia,

    1. To add a select to the add/edit post:
    Follow instructions from ShibaShake tutorial and add your custom taxonomy panel in your theme’s functions.php file.

    It may look like this:

    /**
     * Add a select dropdown for a custom taxonomy
     * in WP User Frontend add/edit frontend form
     *
     * @uses wpuf_add_post_form_after_description action hook
     *
     * @param string $post_type the post type of the post add screen
     * @param object|null $post the post object
     */
    
    function wpufe_add_taxonomy_select( $post_type, $post = null) {
        ?>
    
        <label for="taxonomy_name">
                Taxonomy <span class="required">*</span>
        </label>
        <?php 
    
        // Add security nonce check
        wp_nonce_field( __FILE__, 'taxonomy_noncename' );
    
        // Get all taxonomy terms
        $taxonomies = get_terms('taxonomy_name', 'hide_empty=0');
        // You can also use - see below:
        // $taxonomies = wp_get_object_terms( $post->ID, 'taxonomy_name', array('fields' => 'ids') );
    
        ?>
    
        <?php
    
        // Here is another way to create your dropdown select with WordPress:
        // wp_dropdown_categories('taxonomy=taxonomy_name&hide_empty=0&orderby=name&name=select_name&show_option_none=Select Taxonomy&selected='.$taxonomies[0]);
    
        ?> 
    
        <select name='select_name' id='select_name' class="requiredField">
        <option value='' <?php if (!count($taxonomies)) echo "selected='selected'";?>>Select an item</option>
        <?php
    	foreach ($taxonomies as $taxonomy) {
                    $selected = (has_term($taxonomy->slug, 'taxonomy_name', $post->ID)) ? ' selected="selected" ' : '';
    		echo "<option value='" . $taxonomy->name . "' " . $selected . ">" . $taxonomy->name . "</option>\n";
    	}
        ?>
        </select>    
    
        <?php
    }
    
    add_action( 'wpuf_add_post_form_after_description', 'wpufe_add_taxonomy_select', 10, 2 );

    You can change the final position of your select in the form by modifying the preformatted position (here: wpuf_add_post_form_after_description) by one of the others you can found in Tareq’s tutorial.

    2. Then to save the select, add the suggested saving function I posted above after the wpufe_add_taxonomy_select function.

    3. Change ‘select_name’ and ‘taxonomy_name’ by the select/taxonomy names you chose everywhere you found them.

    Hope it will help you. These functions could probably be improved of course, since I am not a PHP wizard.

    Hello!
    I´m also trying to add my custom taxonomies but I think I have tried everything, without any result. Grandin, dit the above code work for you, and how did it work? I tried but it doesnt seem to work.
    My problem is that i want to add my taxonomy like the regular category-fields. I dont know if thats what the above code does.
    If someone have a solution, any one, Im all ears!

    I´m sorry, it works great! The taxonomy select is there and everything. But it doesnt get saved. Any ideas?

Viewing 15 replies - 1 through 15 (of 35 total)
  • The topic ‘[Plugin: WP User Frontend] Custom Taxonomies’ is closed to new replies.