• Bonjour,
    je voudrais utiliser la fonction wp_create_category() afin de permettre à un client de creer une nouvelle categorie (site d’annonces) mais cette fonction semble n’être utilisable quand back, comment faire en front , merci ?

    Hello,
    I would like to use the wp_create_category () function in order to allow a client to create a new category (ad site) but this function seems to be usable only in Back, how to do it in front, thank you?

Viewing 4 replies - 1 through 4 (of 4 total)
  • @ericebdy

    What method are you currently using to allow users to submit a blog post to your site ?
    And are they anonymous, or logged ? If they are logged in, what Role are they being assigned ?

    Moderator bcworkz

    (@bcworkz)

    It can be used on the front end. But there is nothing to call it by default, you need to add your own code to use it. One way is to use a custom page template. On normal GET requests it outputs a small form to collect the pertinent data. On submit, the form POSTs to its own page.

    When a POST request is received by the page, the template code collects the passed data. The request is checked for security: Is the nonce valid? Does the user have the right capability? The data is validated and sanitized. Then the code can call wp_create_category().

    Thread Starter ericebdy

    (@ericebdy)

    Hello, thank you for your answers.
    for now I am on a local server, and I am trying as an admin.
    I’m just starting out in wordpress and php, I did well as bcworkz explains (nonce, user rights and Data are OK), but for now it doesn’t always work the same error :
    Fatal error: Uncaught Error: Call to undefined function wp_create_category()

    Moderator bcworkz

    (@bcworkz)

    That’s generally caused when a PHP file is directly requested without first going through WP. I think every single person starting out with custom WP coding has made that same mistake 🙂 If you have code that uses WP functions, there are really only 3 ways to execute it while first going through WP. Ajax requests through /wp-admin/admin-ajax.php, GET or POST requests through /wp-admin/admin-post.php, or a custom page template as part of a child theme.

    You might see examples on the ‘net which invoke the WP environment by including wp-load.php or similar initialization files. That is a poor practice as it’s not always portable to other installations. It’s best to do this the right way from the start.

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

The topic ‘wp_create_category() in front’ is closed to new replies.