WordPress.org

Ready to get started?Download WordPress

Forums

Problem with custom posts can someone please help me (2 posts)

  1. Dmitry
    Member
    Posted 1 year ago #

    run a vote exchange website, users register for my site then fill out a form to post their request on my site,This site is build using custom post type “contest” in wordpress and many custom fields. The contests are ordered by using a custom field named “Top Contest Order”. Once a form is submitted its supposed to be posted right away to the site. But some posts are left in Admin and I have to manually approve them to post on the live site. If the custom fields are not added it doesn't post on the live site
    The strange thing is it only happens to 10 percent of users for other users its fine, I have not figured out any viable solution how to fix this problem, I'm using a cache program I tried switching the order of how posts are listed I have many custom fields so I don't have the slightest clue what is causing this and its really frustrating can someone with any wordpress experiences give me some type of solution.

    [ http://codex.wordpress.org/Forum_Welcome#No_Bumping - provide more relevant information instead]

  2. Dmitry
    Member
    Posted 1 year ago #

    Here is the code that is used on the front page to submit the posts maybe something seems out of the ordinary?

    <?php
    
    /*
    
    Template Name: Add Contest
    
    */
    
    get_header();
    
    if(isset($_REQUEST['contest_submit']))
    
    {
    
    		if ($_FILES["image_name"]["error"] > 0)
    
    		{
    
    			//echo "Error: " . $_FILES["full"]["error"] . "";
    
    		}
    
    		else
    
    		{
    
    			$image_size= $_FILES["image_name"]["size"]/1024;
    
    			$image_size_mb = $image_size/1024 ;
    
    			if( $image_size_mb > 4)
    
    			{
    
    			?>
    
    <script type="text/javascript">
    
    					alert("Image size should be less than 4 mb.");
    
    					window.location="index.php";
    
    				</script>
    
    <?
    
    			}
    
    			$image_name = rand(1,999).trim($_FILES["image_name"]["name"]);
    
    		 	$target_image_path=SK_COTNEST_IMAGE_PATH_IMAGES."/".$image_name;
    
    		 	move_uploaded_file($_FILES["image_name"]["tmp_name"],$target_image_path);
    
    		}
    
    			//alert("test");
    
    		global $current_user;
    
    		get_currentuserinfo();
    
    		$userId=$current_user->ID;
    
    		$username=strip_tags($_POST['username']);
    
    		$email =strip_tags($_POST['email']);
    
    		$title=strip_tags($_POST['title']);
    
    		$sponsor_name=strip_tags($_POST['sponsor_name']);
    
    		$website_url=strip_tags($_POST['website_url']);
    
    		$instruction=strip_tags($_POST['instruction']);
    
    		$e_date=strip_tags($_POST['end_date']);
    
    		$end_date=date("Y-m-d",strtotime($e_date));
    
    		$votes_allow=strip_tags($_POST['votes_allow']);
    
    		$social_networking=strip_tags($_POST['social_networking']);
    
    		//$additional_comment=strip_tags($_POST['additional_comment']);
    
    		$cur_date=date("Y-m-d");
    
    		$validation_error=0;
    
    		if($title=="")
    
    		{
    
    			$required_field_text="Title";
    
    			$validation_error=1;
    
    		}
    
    		$validation_error;
    
    		$contest_exist=0;
    
    		global $wpdb;
    
    		/*if($wpdb->get_row("SELECT post_title FROM ".$wpdb->prefix."posts WHERE post_title = '" . $title . "' and post_author= '" . $userId . "'"))
    
    		{
    
    			$contest_exist=1;
    
    		?>
    
    <script type="text/javascript">
    
    					alert("This contest name already Exist, please try another name.");
    
    					window.location.href='index.php';
    
    				</script>
    
    <?
    
    		}
    
    		else*/ if($validation_error==0)
    
    		{
    
    					global $current_user;
    
    					get_currentuserinfo();
    
    					$username=$current_user->user_login;
    
    					$userId=$current_user->ID;
    
    				  $my_post = array(
    
    				 'post_title' => $title,
    
    				 'post_content' => '',
    
    				 'post_status' => 'publish',
    
    				 'post_author' => $userId,
    
    				 'post_type' => 'contest',
    
    				 'post_date' => $cur_date,
    
    				);
    
    			// Insert the post into the database
    
    			// check if title $my_post_name already exists in wpdb
    
    			  $post_id=wp_insert_post( $my_post );
    
    			  $top_contest_order_result=mysql_query("select max(CONVERT(meta_value,SIGNED)) as top from ".$wpdb->prefix."postmeta where meta_key='Top Contest Order'") or die(mysql_error());
    
    			  $top_contest_order_row=mysql_fetch_array($top_contest_order_result);
    
    				$top_contest_order=$top_contest_order_row['top'];
    
    			  //select max(meta_value) from vr_postmeta where meta_key='Top Contest Order'
    
    			 //echo $top_contest_order;exit;
    
    			  $new_contest_order=$top_contest_order+1;
    
    			  add_post_meta($post_id, "Sponsor Name", $sponsor_name, true);
    
    			  add_post_meta($post_id, "Website URL", $website_url, true);
    
    			  add_post_meta($post_id, "Voting Instruction", $instruction, true);
    
    			  add_post_meta($post_id, "Votes Allowed", $votes_allow, true);
    
    			  add_post_meta($post_id, "Social Networking", $social_networking, true);
    
    			  add_post_meta($post_id, "contest_image", $image_name, true);
    
    			  add_post_meta($post_id, 'Top Contest Order',$new_contest_order,true);
    
    			  add_post_meta($post_id, 'end date',$end_date, true);
    
    			  add_post_meta($post_id, 'Send Email',"0", true);
    
    			?>
    
    <script type="text/javascript">
    
    					alert("Contest Submitted Succefully.");
    
    					window.location.href='index.php';
    
    				</script>
    
    <?
    
    		}
    
    }
    
    ?>
    
    <div id="content-sidebar-wrap">
    
      <?php get_sidebar();?>
    
      <div id="content" class="hfeed gform_wrapper">
    
        <h1 class="entry-title"> Welcome to Vote Requests</h1>
    
        <div class="ginput_complex"  style="text-align:justify;" > 
    
          <label style="font-size:16px; font-family:corbel;"> <?php /*?>Fill out the form below to post your contest and/or competition you are in. Vote for other members on the site, by going to, <a>" style="color:#1982D1;" target="_blank">view vote requests</a>. Please leave comments on their post to let them know you voted. 
    
          Do not post duplicate requests for the same contest. To relist the same contest, click on the relisting button and follow the instructions. If you have any other questions, check out our <a>" style="color:#1982D1;" target="_blank">FAQ</a> section or <a>" style="color:#1982D1;" target="_blank">contact us</a> for further assistance. You must be a regiseterd user to request votes. </label>
    
    <?php */?>
    
    	  Complete the form below to post your contest and/or competition you have entered. Vote for other members on the site by going to <a>" style="color:#1982D1;" target="_blank">"View Vote Requests"</a>. Come back often to read comments and return vote favors. The more you vote for others, the more votes you will receive in return.  When you have voted for a member, don't forget to post your vote request link so they know where to go to return the favor.
    
    		NOTE:
    
    		<ul style="list-style:inside;">
    
    <li>
    				DO NOT post duplicate requests for the same contest. To re-list the same contest, click on the "Re-listing" button and follow the instructions. Duplicate requests will be deleted
    
    </li>
    <li>
    				If you have any other questions, check out our <a>" style="color:#1982D1;" target="_blank">FAQ</a> section or <a>" style="color:#1982D1;" target="_blank">contact us</a> for further assistance.
    
    </li>
    <li>
    				Posting a request on this site is a privilege.  By posting a request you are not entitled to votes. You must vote for other members on the site and post your vote number where applicable. We will start deleting posts that do not return votes.  Check your post often and return all vote favors!
    
    </li>
    			<hr />
    
    		<p style="color:#368B2C;font-size:16px;">NEW WEBSITE</p>
    
    		<p>	Need extra traffic for your ebay, amazon, or craigslist listing? Post your item on "<a href="http://www.flipmylisting.com">Flip my listing</a>" for free to get extra exposure.</p>
    
    	  <script type="text/javascript"><!--
    
    		google_ad_client = "ca-pub-1928026304727010";
    
    		/* contest */
    
    		google_ad_slot = "3608370782";
    
    		google_ad_width = 468;
    
    		google_ad_height = 60;
    
    		//-->
    
    		</script>
    
    		<script type="text/javascript"
    
    		src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    
    	  </script>
    
        </div>
    
        <?php
    
    				if ( is_user_logged_in() ) {
    
    					global $current_user;
    
    					get_currentuserinfo();
    
    					$username=$current_user->user_login;
    
    					$userId=$current_user->ID;
    
    				} else {
    
    						$username="Name";
    
    					?>
    
        <div class="login_message"> Please login to add contest. </div>
    
        <?
    
    				}
    
    				?>
    
        <?php
    
    				if ( $contest_exist==1 ) {
    
    					?>
    
        <div class="login_message"> This Contest already exist. Please try another contest or relist existing contest. </div>
    
        <?
    
    				}
    
    				?>
    
        <div class="form-container">
    
          <form id="post" method="post" action="<?php echo bloginfo("url");?>/index.php" name="post" enctype="multipart/form-data" onsubmit="javascript:return empty_check();">
    
            <div class="metabox-holder has-right-sidebar" id="poststuff">
    
              <script type="text/javascript">
    
    					 	function text_clean(input_id)
    
    						{
    
    							if(document.getElementById(input_id).value!="")
    
    							{
    
    								document.getElementById(input_id).value="";
    
    							}
    
    						}
    
    						function empty_check()
    
    						{
    
    							if(document.getElementById("username").value=="" )
    
    							{
    
    								alert("Please Enter Username.");
    
    								document.getElementById("username").focus();
    
    								return false;
    
    							}
    
    							if(document.getElementById("contest_title").value=="" || document.getElementById("contest_title").value=="Contest Name" )
    
    							{
    
    								alert("Please Enter Contest Name.");
    
    								document.getElementById("contest_title").focus();
    
    								return false;
    
    							}
    
    							if(document.getElementById("website_url").value=="" || document.getElementById("website_url").value=="Website URL" )
    
    							{
    
    								alert("Please Enter Website URL.");
    
    								document.getElementById("website_url").focus();
    
    								return false;
    
    							}
    
    							if(document.getElementById("instruction").value=="" || document.getElementById("instruction").value=="Voting instructions for the Contest")
    
    							{
    
    								alert("Please Enter Voting Instuctions.");
    
    								document.getElementById("instruction").focus();
    
    								return false;
    
    							}
    
    							if(document.getElementById("datepicker").value=="" || document.getElementById("datepicker").value=="End Date" )
    
    							{
    
    								alert("Please Select End Date.");
    
    								document.getElementById("datepicker").focus();
    
    								return false;
    
    							}
    
    							if(document.getElementById("votes_allow").value=="" )
    
    							{
    
    								alert("Please Select Votes Allowed.");
    
    								document.getElementById("votes_allow").focus();
    
    								return false;
    
    							}
    
    							if(document.getElementById("captcha").value=="" || document.getElementById("captcha").value=="Type the numbers" )
    
    							{
    
    								alert("Please Enter Captcha Numbers.");
    
    								document.getElementById("captcha").focus();
    
    								return false;
    
    							}
    
    							else
    
    							{
    
    								var captcha=document.getElementById("session_captcha").value;
    
    								if(captcha!=document.getElementById("captcha").value)
    
    								{
    
    									alert("Please Enter Correct Captcha Numbers.");
    
    									document.getElementById("captcha").focus();
    
    									return false;
    
    								}
    
    							}
    
    							if(document.getElementById("terms").checked==false)
    
    							{
    
    								alert("Please accept terms and conditions.");
    
    								document.getElementById("terms").focus();
    
    								return false;
    
    							}
    
    						}
    
    					 </script>
    
              <div id="post-body">
    
                <div id="post-body-content">
    
                  <div id="titlediv">
    
                    <div class="form-required"  style="text-align:right;" >
    
                      <label>* Indicates Required Field</label>
    
                    </div>
    
                    <div style="height:15px;"> </div>
    
                    <div class="form-required">
    
                      <input type="text" aria-required="true" size="70" value="<?=$username;?>" id="username" name="username" 	readonly="readonly">
    
                       * </div>
    
                    <div style="height:15px;"> </div>
    
                    <div class="form-required">
    
                      <input type="text" aria-required="true" size="70" value="Contest Name" id="contest_title" name="title" onfocus="javascript:if(this.value=='Contest Name'){ this.value=''}" onblur="javascript:if(this.value==''){ this.value='Contest Name'}">
    
                       * </div>
    
                    <div style="height:15px;"> </div>
    
                    <div class="form-required">
    
                      <input type="text" aria-required="true" size="70" value="Sponsor Name" id="sponsor_name" name="sponsor_name" onfocus="javascript:if(this.value=='Sponsor Name'){ this.value=''}" onblur="javascript:if(this.value==''){ this.value='Sponsor Name'}">
    
                    </div>
    
                    <div style="height:15px;"> </div>
    
                    <div class="form-required">
    
                      <input type="text" aria-required="true" size="70" value="Website URL" id="website_url" name="website_url" onfocus="javascript:if(this.value=='Website URL'){ this.value=''}" onblur="javascript:if(this.value==''){ this.value='Website URL'}">
    
                       * </div>
    
                    <div style="height:15px;"> </div>
    
                    <div class="form-required">
    
                      <textarea name="instruction" id="instruction" rows="5" style="width:530px;" onfocus="javascript:if(this.value=='Voting instructions for the Contest'){ this.value=''}" onblur="javascript:if(this.value==''){ this.value='Voting instructions for the Contest'}">Voting instructions for the Contest</textarea>
    
                      * </div>
    
                    <!--<link type="text/css" href="<? echo SK_CONTEST_CSS_URL;?>/ui.datepicker.css" rel="stylesheet" />
    
    			<link type="text/css" href="<? echo SK_CONTEST_CSS_URL;?>/ui.theme.css" rel="stylesheet" />
    
    			<link type="text/css" href="<? echo SK_CONTEST_CSS_URL;?>/ui.core.css" rel="stylesheet" />
    
    			<script type="text/javascript" src="<? echo SK_CONTEST_JS_URL;?>/ui.datepicker.js"></script>
    
    -->
    
                    <script>
    
    							  	jQuery(function($) {
    
    									$( "#datepicker" ).datepicker({
    
    										showOn: "button",
    
    										buttonImage: "<? bloginfo("template_url")?>/images/calendar.gif",
    
    										buttonImageOnly: true
    
    									});
    
    								})
    
    							  </script>
    
                    <div style="height:15px;"> </div>
    
                    <div class="form-required">
    
                      <input type="text" size="20" value="End Date" id="datepicker" name="end_date">
    
                       * </div>
    
                    <div style="height:15px;"> </div>
    
                    <div class="form-required">
    
                      <input type="file" id="image_name" name="image_name">
    
                    </div>
    
                    <div style="height:15px;"> </div>
    
                    <div class="form-required">
    
                      <select title="Votes Allowed" id="votes_allow" name="votes_allow">
    
                        <option value="" >Votes Allowed :</option>
    
                        <option value="One Time Only" >One Time Only</option>
    
                        <option value="Daily" >Daily</option>
    
                        <option value="Weekly" >Weekly</option>
    
                        <option value="Other" >Other</option>
    
                      </select>
    
                      * </div>
    
                    <div style="height:15px;"> </div>
    
                    <div class="form-required">
    
                      <select title="Social Networking" id="social_networking" name="social_networking">
    
                        <option value="" >Social Networking :</option>
    
                        <option value="Facebook" >Facebook</option>
    
                        <option value="Twitter" >Twitter</option>
    
                        <option value="Other" >Other</option>
    
                      </select>
    
                    </div>
    
                    <div style="height:15px;"> </div>
    
                    <div>
    
                      <?
    
    									$fid = rand(10000, 99999);
    
    									if (!session_id())
    
    										session_start();
    
    									$captcha_name = 'ccf_captcha_' . $fid;
    
    									if (!$_SESSION[$captcha_name])
    
    										$_SESSION[$captcha_name] = $fid;
    
    									else
    
    										$fid = $_SESSION[$captcha_name];
    
    								?>
    
                      <input type="hidden" name="session_captcha" id="session_captcha" value="<? echo $_SESSION['ccf_captcha_'.$fid];?>">
    
                      <img width="96" height="24" src="<? echo WP_PLUGIN_URL;?>/custom-contact-forms/image.php?fid=<? echo $fid;?>" id="captcha-image" alt="Captcha image for Custom Contact Forms plugin. You must type the numbers shown in the image">
    
                      <div>
    
                        <input type="text" maxlength="20" id="captcha" name="captcha" value="Type the numbers" onfocus="javascript:if(this.value=='Type the numbers'){ this.value=''}" onblur="javascript:if(this.value==''){ this.value='Type the numbers'}">
    
                      </div>
    
                    </div>
    
                    <div style="height:15px;"> </div>
    
                    <div class="form-required">
    
                      <input type="checkbox" value="1" id="terms" name="terms">
    
                      I agree with the <a>" style="color:#1982D1;" target="_blank">User Terms</a> of voterequests.com </div>
    
                  </div>
    
                  <div style="height:10px;"> </div>
    
                  <div style="width:300px;margin-left:100px;">
    
                    <input type="submit" name="contest_submit" value="Submit" class="submit_bg" <? if(!is_user_logged_in()) {?> disabled="disabled" <? }?>>
    
                     
    
                    <input type="reset" value="Reset Form" class="submit_bg">
    
                  </div>
    
                </div>
    
              </div>
    
              <br class="clear">
    
    		  <p style="color:#368B2C;">Attention!
    
    			We are seeking a volunteer editor/moderator for our site. We are looking for someone who enters contests and sweepstakes regularly. If you're interested contact us for further details. 
    
    		  </p>
    
            </div>
    
            <!-- /poststuff -->
    
          </form>
    
        </div>
    
      </div>
    
    </div>
    
    <?php get_footer();?>

    [how to post code: http://codex.wordpress.org/Forum_Welcome#Posting_Code - the above code was first posted without being marked, and might be partly ccorrupted]

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.