Forums

[Plugin: Custom Field Template] Manual Related Post (4 posts)

  1. jdvroum
    Member
    Posted 5 months ago #

    Hello,

    I need help to create a custom field for related post.
    I would like to choose in one list whish contain all the post of my blog (the id and the title or only of them).
    In my post, I would like to show the title of the related post and when I clic on it, I go to the post

    Thanks for your help
    Excuse my english
    Julien

  2. randyhoyt
    Member
    Posted 5 months ago #

    Do you want this field to be a select list from which you can pick on related post?

  3. vladaju
    Member
    Posted 5 months ago #

    yes I would like this, related post from my website...
    Do you have an idee to help me ?

    Thanks
    Julien

  4. randyhoyt
    Member
    Posted 4 months ago #

    Here's some code for the field that goes in the template definition section:

    [Related_Post_ID]
    type = select
    code = 0
    hideKey = true
    label = Related Post

    The attribute code = 0 references the PHP code section further down the page. The following code should go in the PHP Code section, in the Code #0 box.

    global $wpdb;
    $items = $wpdb->get_results("SELECT ID, post_title
    FROM $wpdb->posts
    where post_type = 'post'
    and post_status = 'publish'
    order by post_date DESC");
    $i = 0;
    foreach ($items as $item) {
    	$values[$i] = $item->ID;
    	$valueLabel[$i] = $item->post_title;
    	$i++;
    }

    If all goes well, this will give you a dropdown list of all your posts.

Reply

You must log in to post.

About this Topic