Skip Navigation

[Resolved] Display related posts chosen in the backend

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 3 replies, has 3 voices.

Last updated by Minesh 8 months, 3 weeks ago.

Assisted by: Minesh.

Author
Posts
#2690758

Hello!

I have created a dictionary with definitions with the help of Toolset. The pages with definitions are custom post types, while the page with the dictionary (i.e. the list of definitions) is custom archive.

The archive page is available here: hidden link
An example definition page is available here: hidden link

Some of the definitions (e.g. "SEO", "Black Hat SEO" and "Content-marketing") are related. I would like to be able to easily select which definitions are related and then display links to those definitions at the bottom of the post, under the 'Related Definitions' heading.

It seemed to me that the best way would be to use relationships, but this is impossible for the same type of post.

The second idea was to use tags. On this page hidden link, I display View with posts that have the same tag as the post being displayed (under 'Powiązane definicje' heading).

However, the way with tags is not what I am looking for, because not all definitions from a given tag will be related to each other.

How can I solve this problem?

P.S. I am using the content template and displaying custom fields on the definition page.

#2690801

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

I think you may want to create another custom taxonomy like tags specifically to connect posts that are "related" (where "related" means you want to show them in a related definitions section).

An alternative could be, say, to have a custom field where you add details of the other posts related to the current one, but there is no simple way to have a friendly UI for that, inasmuch as you would essentially just be storing a comma-separated list of post IDs, and entering those manually.

Is a custom taxonomy similar to tags for this purpose viable?

#2691075

Unfortunately, the way with tags will not work, because not all definitions inside a tag will be related to each other.

For example, it may be that definition A will be related to definitions B and C, but not related to definition D. In turn, definition D will be related to definitions B and C. The use of tags in such a case is not possible.

The way with manually adding a comma-separated list of posts (preferably with typing the post name, not the ID) sounds the most accessible. How can I do this?

#2691098

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

To display the post with multi select there is no such option.

The only possible workarrounds are:
- You will have to add the post IDs as comma separated string
- Add a repeating field group

The idea with " Add a repeating field group" is - you can add a repeating field group with title "Related Definitions" and add a custom select field to this repeating field group with title "Related" and save the field group.

Then you can navigate to "Custom Code" section and add the following code:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

add_filter( 'wpt_field_options', 'prefix_custom_options', 10, 3);
 function prefix_custom_options( $options, $title, $type ){
    switch( $title ){
        case 'Related':
            $options = array();
            $args = array(
                'post_type'        => 'book',
                'post_status'      => 'publish');
            $posts_array = get_posts( $args );

  $options[] = array(
                    '#value' => '',
                    '#title' => 'Please Select',
                );

            foreach ($posts_array as $post) {
                $options[] = array(
                    '#value' => $post->ID,
                    '#title' => $post->post_title,
                );
            }
            break;
    }
    return $options;
}

Where:
- Replace 'book' with your desired post type slug you want to display as select option to select post.
- Replace 'Related' with you custom select field title.

Then Add a new post and try to add repeating field group item and you will able to add the multiple post now.

More info:
- https://toolset.com/documentation/programmer-reference/types-api-filters/#wpt_field_options

This is a workaround you should try, hopefully it will help you.