SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Mar 2012
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wordpress Anthology

    If I have questions regarding any topics covered in The Wordpress Anthology book offered on this site, would this be the proper forum to present them?

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,189
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)
    As best a place as any. What do you got?

  3. #3
    SitePoint Member
    Join Date
    Mar 2012
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the author is explaining how to incorporate a form element as part of an edit screen to a custom post. The following code is an excerpt. I don't understand the function of the $post variable. I'm assuming the $custom variable is essentially the PHP equivalent of $_POST[ ]. What I don't understand is how the post ID is referenced.
    $custom = get_post_custom($post->ID);
    I was also confused about the second subscript in the $custom[ ] index until I glanced at the codex. I noticed that the codex doesn't bother referencing the second subscript.
    Can anyone explain to me the function of the $post variable and the post->ID reference in the following code?

    Code PHP:
    <?php
    //......
    function conference_speaker_fields (){
    	global $post;
    	$custom = get_post_custom($post->ID);
    	$conference_speaker_business = $custom["conference_speaker_business"][0];
    	$conference_speaker_website_name = $custom["conference_speaker_website_name"][0];
    	$conference_speaker_website_url = $custom["conference_speaker_website_url"][0];
    	$conference_speaker_location = $custom["conference_speaker_location"][0];
    	?>
    	<p>
    	<label>Employer/Business Name:</label><br />
    	<input size="45" name="conference_speaker_business" value="<?php echo $conference_speaker_business; ?>" />
    	</p>
    	<p>
    	<label>Website Name:</label><br />
    	<input size="45" name="conference_speaker_website_name" value="<?php echo $conference_speaker_website_name; ?>" />
    	</p>
    	<p>
    	<label>Website URL:</label><br />
    	<input size="45" name="conference_speaker_website_url" value="<?php echo $conference_speaker_website_url; ?>" />
    	</p>
    	<p>
    	<label>Location:</label><br />
    	<input size="45" name="conference_speaker_location" value="<?php echo $conference_speaker_location; ?>" /></p>
     
    	<?php
    }
    Last edited by Mittineague; Jun 4, 2013 at 17:51. Reason: reformatting bbcode tags

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,189
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)
    Hopefully this helps.

    The $post object (as in "blog post", not "form fields") contains various values.
    get_post_custom() uses the ID and returns a multi-dimensional array.
    http://codex.wordpress.org/Function_...et_post_custom

    So $custom["conference_speaker_business"] is not a value but an array that may or may not contain more than one value pairs. It looks like in this example, it is only a single value, hence array key "0".


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •