• I’m running WP 2.2 and what I’m trying to do is add two fields to the wp_posts TABLE.

    I’d like to add post_source and post_url, which I can do via phpMyAdmin. What my question is how/where do I declare these so I can use template tags in my theme to call them?

Viewing 9 replies - 16 through 24 (of 24 total)
  • alright, thanks for your answer. i have just one more question:

    as you know the_title(); prints the title of that particular post when used in the loop. and that title of the post is stored in the database table wp_posts.

    i have added an extra field in that database table (wp_posts) lets call it the second title and i want to copy the code that makes the function the_title(); work and i want to use that code to make an extra function i.e. the_second_title(); or so.

    i dont want you to write any code for me but i just want to know where exactly that piece of code that makes the_title(); function work. i will copy and modify it and i will have an extra function that prints the value of the extra field i had added to the database table wp_posts. each of the rows of that table has a value for this newly added field.

    so what i want you to do is just give me the location of the code that queries the database and prints the value that is stored in the title field of the database table wp_posts. i am planning to copy it paste it and modify it to work for the new field i that i added to the table…

    Actually, you’re just making a bunch of extra unnecessary work for yourself…WordPress can do what you want by default.

    If you want a “Subtitle”, there’s a couple of ways you can do it. One way is simply to put in the title when you’re writing posts, and the first thing in your actual post content, put something like <p class="subtitle">Subtitle text here</p> and then start writing your content.

    But another method (that’s more in line with what you’re trying to do) is to scroll down in your “Write Post” section, and you’ll see a section called “Custom Fields”. You want to ignore the dropdown for the first one, but on the next (text) field, type in something like subtitle and in the “Value” field, type in what you want for the subtitle. Click “Add Custom Field” and it’s now been written to your database, and forever from now, you can click the dropdown and select that Key, and write in any value you want. In the future, you can query the database an and pull out the subtitles by meta, if you want – but you don’t need to yet.

    Now, to display it – I’m assuming you want the subtitle to show right beneath the title of the post – you open up your index.php file, and under the “post_title” part (it *has* to be in the Loop, so if you don’t want it there, just be sure to get it in the Loop somewhere), put in:

    `$key = “subtitle”;
    get_post_meta($post_id, $key, $single);`

    and it’ll display your meta stuff for you.

    You can read up on Custom Fields here.

    thank you for your attention and time. but i already know all about WP custom fields. but the problem is that the custom field data are stored in a different database table then wp_posts. i prepare my database manually and i update my database from phpmyadmin (because of the different type of work i do with WP) and the only thing i need is to make some extra functions that would display the extra data fields of my posts. WP’s default custom fields would be useful for me if only it stored its data in the database table wp_posts.

    anyhow, if you know what i should do to mimic the_title function and make my own function just to print the value of the extra data field i added to the database wp_posts please guide me.. thanks again

    Well, you *could* just do your database selection with “where” and “as ” statements to reference the post to the custom field.

    But otherwise, I don’t know where the_title stuff is stored. My *guess* would be in the wp-includes folder, under the “functions.php” file – but I’m not positive. But you probably wouldn’t need to go that far to emulate things. You could just write a function that queries the database and echoes out the new field with the post (which really, using the custom fields, you’d be doing exactly the same thing)

    Something like (this uses the custom fields query I was talking about):

    function subtitle() {
    $subtitle = $wpdb->get_results("SELECT * FROM $wpdb->posts, $wpdb->postmeta WHERE $wpdb->postmeta.post_id = $wpdb->posts.post_id");
    }

    and then you may be able to just insert that in your index.php file:

    <?php if (have_posts) : while (have_posts) : the_post();?>
    <h2><?php the_title(); ?></h2>
    </h3><?php echo subtitle(); ?></h3>

    I doubt that will work straight out of the box like this (MySQL coding isn’t my strong suit) – I’m sure there’s more to it but that should give you some idea on how to do it.

    i will try it and inform you as soon as possible.

    by the way are you in WP team?

    WP Team? If you mean “someone who helps develop it”, no. I just use it a lot ??

    i think we have a syntax error at the function somewhere because when i add that function to functions.php then the site crashes

    oh wait.. i think i made a small mistake. now the site does not crash

    I am trying to implement a copy of the function the_title() lets call it the_secondtitle();

    I added a new database field just near post_title field in wp_posts database table lets call it post_secondtitle

    i want to have a the_secondtitle(); function that behaves exactly as the_title(); function except that it pulls the value from post_secondtitle database field rather than the original post_title field.

    I know all about custom fields but as the custom field databse sits in another table than the wp_posts table i dontwant to use customfields function.

    Can you describe me what to add to my functions.php to have an extra function called the_secondtitle(); that would bring the value that sits in post_secondtitle database field that is in the wp_posts database table?

Viewing 9 replies - 16 through 24 (of 24 total)
  • The topic ‘Add fields to post’ is closed to new replies.