Forums

how can I show post title? (9 posts)

  1. ricardodias
    Member
    Posted 1 year ago #

    Hi there!
    I've a template that's using custom field for the post title.

    The problem is that I've an old database and the new theme does not recognize the post titles. And if I write a new post and put the title in the normal field it doesn't appear. It only recognizes the custom field.

    What I have in the current theme is:

    <?php if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    		<?php
    		$mypost = get_post($post->ID);
    		$posttime = $mypost->post_date;
    		...

    I would like to know how can I "call" the old database post title when I don't have a post with the title custom field. Maybe with an "else"?

    Thanks for your time and help!

  2. VelvetBlues.com
    Member
    Posted 1 year ago #

    For new titles:

    the_title();

    or in the same nethod as above:

    $title = $post–>post_title;

    For custom fields:

    $key="title";
    $metatitle = get_post_meta($post->ID, $key, true);
    echo $key;

    Very verbose... but you can simplify it.

    So, putting it all together:

    if (isset($metatitle)){
    // do something, echo perhaps?
    }
    else{
    // echo normal title?
    }
  3. ricardodias
    Member
    Posted 1 year ago #

    Velvet, tkx for the fast reply.
    This is my index.php function to call the post (it only show the info of the post, not the content):

    <?php
    		$mypost = get_post($post->ID);
    		$posttime = $mypost->post_date;
    		$posttime = explode(" ", $posttime);
    		$currenttime = current_time(mysql);
    		$currenttime = explode(" ", $currenttime);
    		$inposttime = $posttime[0];
    		$inposttime = explode("-", $inposttime);
    		$incurrenttime = $currenttime[0];
    		$incurrenttime = explode("-", $incurrenttime);

    How do I get it to show the normal title of the posts (old database) when we don't write it on the custom field?

    My problem is that I can only see the info of the posts inserted on the custom fields and not the post titles of the normal post editor.

    Thanks!

  4. VelvetBlues.com
    Member
    Posted 1 year ago #

    To get the title, you can usually just use $post->post_title or to echo, the_title(). And if $post->ID works, $post->post_title should work as well.

    But this seems like a very special case, so please let me know what database & version you are running, as well as what version of WordPress you are using.

  5. ricardodias
    Member
    Posted 1 year ago #

    I have a form_process.php where I get this:

    $jobtitle 		= $_POST['jobtitle'];
    ...
    $post_title	 	 = ''.$jobtitle." at ".$companyname.'';
    $post_name = $post_title;

    Can we do something here to call the normal title in case I have the custom field for the title in blank?

    I'm using the theme on MAMP, under 2.5.1 wordpress.

  6. VelvetBlues.com
    Member
    Posted 1 year ago #

    And the plot thickens...

    I am lost. Where did $jobtitle come from? So your users are posting a job? Or searching for a job?

    If the latter, they can just use a normal search and then you'd configure the search template.

    If the former, then you are creating new posts based on what users submit? (I'd probably modify the comments form & template for this.) Look up custom queries in the WP documentation. You'll use the wordpress var $wpdb to insert a new post...

    Sorry. I don't know if that helped, but I have no idea what you are trying to do... (Since your last theme worked, you might just look and see what was done in the last theme.)

    Good luck.

  7. ricardodias
    Member
    Posted 1 year ago #

    In the last theme it was me who inserted the job offers manually, post by post.
    In this new theme the users post the offers through a form process based on custom fields.
    The problem is that the new theme doesn't recognize the old post titles in the index.php. It shows the entry but there's no title and, for that, no link to the correspondent single page...
    :(

  8. VelvetBlues.com
    Member
    Posted 1 year ago #

    Ok. Thanks for the full disclosure. :-)

    So, you need to have an actual title or url to link to a post. The title can be anything. Have you taken a look at your database? Are urls being created?

    If so, you can just pull any title and then use $post->guid to pull up the corresponding url.

    For example:

    foreach($posts as $post){
    $url = $post->guid;
    $title = $post->title;
    if(!isset($title) || trim($title)==''){
    $title = get_post_meta($post->ID, 'title', true);
    }
    echo "<a href=\"$url\">$title</a>";
    }
  9. ricardodias
    Member
    Posted 1 year ago #

    VB, thanks for the help, but I can't make it work
    :(
    I think I'll have to find a programmer who can help me with this problem...
    If I found the solution for this, I'll post it later.
    Thanks and regards!

Topic Closed

This topic has been closed to new replies.

About this Topic