Skip to:
Content
Pages
Categories
Search
Top
Bottom

Missing title in replies


  • Clivesmith
    Participant

    @clivesmith

    Is there a reason that the title of the topic does not automatically get carried over to the replies record, is there a way to force it.
    I am trying to post topics and replies to social media but when it is a reply the title of the topic is not there which makes the post without context.

    Clive

Viewing 4 replies - 1 through 4 (of 4 total)

  • Clivesmith
    Participant

    @clivesmith

    Hi,
    Still trying to sort this, When I create a new reply is there a way to create a custom field of the topic title?
    I see there are lots of custom fields but not the topic title.

    Clive


    Clivesmith
    Participant

    @clivesmith

    Hi,
    Does anyone know why the post_title is blank in the reply ?
    If I populate the reply post_title with the title from the topic is it going to give me problems ?

    Clive


    Robin W
    Moderator

    @robin-w

    sorry, been working on another project.

    If you fill in the title in the admin of a reply, as far as I know it will cause no issues, I’ve not seen any code that uses this field. I cannot be absolute, but best I can say.


    Clivesmith
    Participant

    @clivesmith

    Hi Robin,
    Thank you for replying.
    I did find something that was said years ago about not putting the topic title into the reply record, not sure why.
    So I create a record in the meta table, which is a custom field in the reply form using the following code and add the topic title as a custom field to the custom message in the Fs Poster plugin I am using to post to social media.

    function check_and_populate_top_title_on_edit() {
    global $pagenow;

    // Check if we are in the post.php page (edit post/reply screen) and in the admin area.
    if ($pagenow === ‘post.php’ && is_admin()) {
    // Get the post ID from the URL query string.
    $post_id = isset($_GET[‘post’]) ? intval($_GET[‘post’]) : 0;

    // If we have a valid post ID, proceed.
    if ($post_id) {
    $post = get_post($post_id);

    // Ensure we’re working with a ‘reply’ post type.
    if ($post && $post->post_type === ‘reply’) {

    // Check if the post title is empty.
    if (empty($post->post_title)) {
    // Get the parent post ID.
    $parent_post_id = $post->post_parent;

    // Check if a parent post exists.
    if ($parent_post_id) {
    // Get the parent post data.
    $parent_post = get_post($parent_post_id);

    // If the parent post exists and has a title, update the ‘top_title’ custom field.
    if ($parent_post && !empty($parent_post->post_title)) {
    // Add or update the ‘top_title’ meta field with the parent post’s title.
    update_post_meta($post_id, ‘top_title’, $parent_post->post_title);
    }
    }
    }
    }
    }
    }
    }

    add_action(‘load-post.php’, ‘check_and_populate_top_title_on_edit’);

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar