WordPress.org

Ready to get started?Download WordPress

Forums

Require assigned taxonomy before publishing is allowed (3 posts)

  1. bknutson
    Member
    Posted 2 years ago #

    In a knowledge base I've built, the user must post a page with a taxonomy assigned to it. This is because static pages for each possible taxonomy query the database for all posts tagged with that taxonomy, and generate a splash/landing page with a list of all relevant posts.

    It did not occur to me that the user may forget to assign a taxonomy to a post, and the post would therefore be lost in the "twilight zone." It exists in the database, has a unique URL, but is linked to nowhere on the website.

    I can go back through the database and fix any past errors, but moving forward what I would like to do is require that a taxonomy be assigned before the user is allowed to publish a post.

    Should I be doing this in PHP in the post-new.php file? Should I use jQuery to check that a value has been assigned, and test on-click of the publish button?

    Thoughts???

  2. bcworkz
    Member
    Posted 2 years ago #

    I like the jQuery idea, it makes more sense for the client to check the form for completeness before POSTing it. Keeps the load off your server. Even with ideal conditions, trying to use PHP will end up being a bit of a kludge.

  3. bknutson
    Member
    Posted 2 years ago #

    Well...so far I haven't been able to determine what exactly I need to test. The below works on click of the Publish button

    jQuery("#publish").click(function() {
    		alert("Please make sure you have chosen a Sub Category!  If you have not, please add one or more and click Update on the next screen.");
    	});

    I thought about something like this:

    if( !$.trim( $('textarea#tax-input-sub').html() ).length ) {
    			event.preventDefault();
    			alert("Please specify a sub category!");
    		};

    However the textarea#tax-input-sub always seems to be empty, even after adding a value to the "Sub Category" taxonomy. I'm not sure what to test on this page.

    Help?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags