WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Link to create new post (2 posts)

  1. Gabriel
    Member
    Posted 3 years ago #

    I know that if I wish to create a link for users to create a new post I can do so by i.e.

    <?php if(is_user_logged_in() && current_user_can('read_notice')) : ?>
    <a href="<?php get_bloginfo('url'); ?>/wp-admin/post-new.php?post_type=notice" title="Contribute">Add New</a>
    <?php endif; ?>

    The code above links to creating a new post (post_type notice) but is there a way I can also force what "custom taxonomy" the post is created in? I have a custom taxonomy called "type" in which I have a specific category called "computers".

    Was thinking maybe:

    /wp-admin/post-new.php?post_type=notice&type=computers

    but that does not work. Any suggestions assuming it is possible to do.

  2. Gabriel
    Member
    Posted 3 years ago #

    I found a solution to this. Using custom meta boxes one just need to intercept the type=computers, put it in a hidden input field and when saving add it to the appropriate taxonomy.

    Intercepting:

    <?php if ( isset( $_GET['type'] ) ) { ?>
    	<input type="hidden" name="presettype" id="presettype" value="<?php echo $_GET['type']; ?>" />
    <?php } ?>

    Then when we save our details:

    if ( !empty( $_POST['presetkeyword'] ) ) {
    	wp_set_object_terms( $post_id, $_POST['presettype'], 'type' );
    }

    Done.

Topic Closed

This topic has been closed to new replies.

About this Topic