Skip Navigation

[Resolved] How to keep child post displaying in View

This support ticket is created 2 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 6 replies, has 3 voices.

Last updated by Waqar 2 years, 8 months ago.

Assisted by: Waqar.

Author
Posts
#2318327
Screenshot 2022-03-16 at 7.12.01 PM.png

Dear Sir/Madam,

I have an ebook, an ebook containing several chapters, using the View, I can have a good outlook to view the chapter and pagination at the footer. I want to allow users to search the content, If I click the search result to a chapter, it can't be shown at the look of using the view. How can I force individual chapters can be viewed as the ebook?

Here is the chapter within a view
hidden link ( this is my expected result )

Here is the search result to one chapter
hidden link

Here is the page I click the link from the search result
hidden link ( this is not my expected result )

#2318587

Nigel
Supporter

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

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

Hi Kelvin

I'm not sure if I have understood your objective.

Am I correct in thinking that you have an ebook post type, and then a chapter post type, which is a child of the ebook type?

And what you want to happen is that when visitors are reading a chapter, there is a search box to enter a text search, which should search the text from all chapters of the ebook, and not just the current chapter.

Is that correct? If you can please confirm before we think about how to implement it.

#2321455

Dear NIgel,

I have parent post type 'ebook' and child post type 'chapter', I custom the content template for 'ebook' including a View with pagination, it is fine to click the pagination to read the chapter one by one. I make the chapter be queryable, I search and get the chapter resuilt, when I click the result and it show chapter post all pagination lost. How can I force the result to read the chapter content like I read the ebook with pagination?

Not sure whether you can get my question.

#2322531

Hi,

Thank you for sharing these details.

To suggest the best way to keep the chapter navigation on the single chapter pages, I'll need to see how all these elements are set up in the admin area.

Can you please share temporary admin login details, in reply to this message?

Note: Your next reply will be private and it is recommended to make a complete backup copy, before sharing the access details.

regards,
Waqar

#2324009

Thank you for sharing these details.

The regular next and previous post links won't work on the single chapter post pages, because your goal is to show only those chapter posts which are related to the same eBook.

In this case, you'll need a custom shortcode, which can generate the next/previous links for you based on the post-relationship. You'll find a good example of this code, in this reply from Christian:
https://toolset.com/forums/topic/next-and-previous-sibling-posts-in-a-one-to-many-post-relationship/#post-1934213

I hope this helps and please let me know if you need any further assistance around this.

#2327399

Dear Waqar,

There is a custom field 'order' to the child post, I need to query the previous and next post, I don't know what is the problem to my code, I can't get the correct order.

    $sibling_args = array(
        'query_by_role'=>'parent',
        'limit'=>1000,
        'role_to_return'=>'child',
        'meta_key' => 'wpcf-ebook-chapter-order',
        'orderby' => 'meta_value_num',
        'order' => 'ASC'
    );
    $siblings = toolset_get_related_posts( $parent_id, $relationship_slug, $sibling_args );

Could you please advise?

Best regards,

Kelvin.

#2328811

Thanks for writing back.

On my test website, I was able to make this work, ordered by the "ebook-chapter-order" custom field, by using slightly updated custom shortcode:


function tssupp_next_prev_child($atts) {

	$a = shortcode_atts( array(
		'current' => 0,
		'step' => '1',
		'relslug' => '',
		'orderfieldslug' => '',
	), $atts );

	$link = '';

	$relationship_slug = $a['relslug'];
	$current_child_id = $a['current'];
	$order_by_field = 'wpcf-'.$a['orderfieldslug'];

	// get the parent post
	$parent_id = toolset_get_related_post( $current_child_id, $relationship_slug );

	if(!empty($parent_id)) {

		$sibling_args = array(
			'query_by_role'=>'parent',
			'limit'=>1000,
			'role_to_return'=>'child',
			'orderby'=>'meta_value_num',
			'order'=>'ASC',
			'args' => [
				'meta_key' => $order_by_field
			]
		);

		$siblings = toolset_get_related_posts( $parent_id, $relationship_slug, $sibling_args );

		// loop over child posts and get index of the current post
		foreach($siblings as $i=>$sibling) {
			if( $sibling == $current_child_id ) {
				break;
			}
		}

		// increment or decrement index for next or previous sibling
		$i += $a['step'];

		// create link to next/previous sibling
		if(isset($siblings[$i])){
			$perm = get_the_permalink( $siblings[$i] );
			$title = get_the_title( $siblings[$i] );
			$link .= $a['step']=='1' ? "Next: " : "Previous: ";
			$link .= "<a href='" . $perm . "'>" . $title . "</a>";
		}

		// output the link, or empty string if not set
		return $link;
	}
}
add_shortcode( 'tssupp-next-prev-child', 'tssupp_next_prev_child' );

And in the content template, used the shortcode the next and the previous links, like this:


// next link
[tssupp-next-prev-child step="1" relslug="ebook-chapter" orderfieldslug="ebook-chapter-order" current="[wpv-post-id]"]

// previous link
[tssupp-next-prev-child step="-1" relslug="ebook-chapter" orderfieldslug="ebook-chapter-order" current="[wpv-post-id]"]