Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8168753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:37:55+00:00 2026-06-06T20:37:55+00:00

I have a WordPress Front End Form to Publish/Draft Posts directly from my theme:

  • 0

I have a WordPress Front End Form to Publish/Draft Posts directly from my theme: –

<?php
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "new_post") {

    // Do some minor form validation to make sure there is content
    $title = $_POST["title"];
    if(!empty($_POST['middle'])) {
    $description = 'a sentence ' . $_POST['middle'] . ' with something in the MIDDLE. a sentence ' . $_POST['end'] . ' with something in the END.';
    }
    $tags = $_POST["tags"];
    $post_cat = $_POST['cat'];

    // ADD THE FORM INPUT TO $new_post ARRAY
    $new_post = array(
    'post_title'    =>  $title,
    'post_content'  =>  $description,
    'post_category' =>  $post_cat,  // Usable for custom taxonomies too
    'tags_input'    =>  $tags,
    'post_status'   =>  'draft',           // Choose: publish, preview, future, draft, etc.
    'post_type' =>  'post',  //'post',page' or use a custom post type if you want to
    );

    //SAVE THE POST
    $pid = wp_insert_post($new_post);

    //REDIRECT TO THE NEW POST ON SAVE
    $link = get_permalink( $pid );
    wp_redirect( '/post-submitted-draft' );

} // END THE IF STATEMENT THAT STARTED THE WHOLE FORM

//POST THE POST YO
do_action('wp_insert_post', 'wp_insert_post');

?>

and I have a simple php form which has the following function: –

<?php
if(!empty($_POST['middle'])) {
   echo "a sentence".$_POST['middle']." with something in the MIDDLE.";
}

if(!empty($_POST['end'])) {
   echo "a sentence".$_POST['end']." with something in the END.";
}
?>

I wanted to include it in the form and I did it using the method below: –

if(!empty($_POST['middle'])) {
$description = 'a sentence ' . $_POST['middle'] . ' with something in the MIDDLE. a sentence ' . $_POST['end'] . ' with something in the END.';

but it will ignore the whole value of $description if the field of ‘middle’ is empty and I want it to ignore just the first sentence if the field of ‘middle’ is empty and display the second sentence which has the field of ‘end’ i.e.

'a sentence ' . $_POST['end'] . ' with something in the END.';

How to make it work like this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T20:37:57+00:00Added an answer on June 6, 2026 at 8:37 pm

    Following a method like below will make the whole thing flow better and make more sense. Basically, setting the description variable to the first sentence and adding the second bit if it exists.

    if(!empty($_POST['middle'])) {
       $description = "a sentence".$_POST['middle']." with something in the MIDDLE.";
    }
    
    if(!empty($_POST['end'])) {
       $description .= "a sentence".$_POST['end']." with something in the END.";
    }
    
    if(isset($description)) {
    // do something with description
    }
    

    Also, think about escaping the strings depending what you are using it for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the WordPress Login form working in the front-end of my website, to
What I want to do is to create a simple front-end post submit form,
I am looking to use wordpress editor via the front end. i have looked
I have configured WordPress to display a static front page as described here: http://codex.wordpress.org/Settings_Reading_SubPanel#Reading_Settings
I have a static front page in Wordpress and I want to use a
My wordpress is not setting the front page correctly, I have several pages, all
I have a wordpress blog www.freelancing4arab.com, I want to change the theme font, I
i have wordpress blog in my custom built website, i am displaying some posts
I have a wordpress theme that has a build in shortcode for creating an
I don't want to use Wordpress' built in media uploader. I have a form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.