Skip Navigation

[Résolu] Can not get correct view details to show

This support ticket is created Il y a 7 années et 10 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Marqué : ,

This topic contains 9 réponses, has 2 voix.

Last updated by Beda Il y a 7 années et 9 mois.

Assisted by: Beda.

Auteur
Publications
#411668
business card view.png
Advertiser-Active with Category View.png

I an trying to get a correct view with a Cpt and parent custom post type but i am getting inconsistent results.

The structure. Advertisers (parent ) with taxonomy (business category). The child cpt (business card to Advertisers is just one field, a image file.

The resulting page must have the following
Parametric search with the Business category taxonomy.

The image of the "business card" and the advertisers name and details.

My current results is as follow:
hidden link

It repeats all the entries in the parent for every entry in the business card post. The second problem is i do not have the Business category taxonomy in the drop down to be able to set the search.

My views are structured as follow:
I made a nested view of the advertiser with a view called "Advertiser-Active with Category View"

This is then used as nested view in "Business card view"

The code used in "Advertiser-Active with Category View" is
The loop output is

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<wpv-loop>
		[wpv-post-body view_template="Loop item in Advertiser with Category View"]
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

The template view is

[types field='company-logo' size='thumbnail' align='left' resize='proportional'][/types]
[types field='company'][/types]<br>
[types field='email-1fbb5d64'][/types]<br>
[types field='active-account'][/types]<br>
[wpv-post-taxonomy type='advertiser-category']<hr><br><br><br>

The code used in "business card view" is
The loop output is

[wpv-post-body view_template="Template for businesscards"][wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<wpv-loop>
		[wpv-post-body view_template="Loop item in Business card view"]
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

The template view is

[types field='businesscard-image' size='medium' align='none' resize='proportional' id='$parent'][/types][wpv-view name="Advertiser-Active with Category View"]

I am attaching the screen shot of both views also

#411680

1. The resulting page must have the following:

- Parametric search with the Business category taxonomy.

Then, you need a View that queries that Post Type directly
This means you must query the Parent Post type Advertisers and add a Paramtric Search for the taxonomy.

- The image of the "business card" and the advertisers name and details.

The Advertiser name and details are easy to add. You just call the fields with our ShortCodes using the GUI in the Views Loop.

The image of the "business card" instead, since it's a Child Pot of Advertiser, must be called in a second View.
This second View queries CPT "business card" and in it's Loop it returns the image.
This View is set to have a Query Filter as:

Select posts that are a children of the current post in the loop.

Then you will insert this second view to the Loop of the first view.

2. If this does not make sense to you, or you need more detailed information, you might find this helpful:
https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/

#411697
query filter section.png

Hi Beda,

Thx for your speedy reply. I have followed your instructions to the letter up to point "This View is set to have a Query Filter as:"

Now here i am getting lost. I have looked everywhere but can not find where to input that sting in. The Query filter option does not give that option.

As far as I understand it must be in the "business card view" view. However if i look at the query filter section for this view there are no options to select that option.
I understand the concept of the parent and child connection it is just how to actually implement it.

#411701

Well, you need to click on "Add a Filter" in the Query Filter section, and then choose "Post relationship - Post is a child of"

Then, you will see the option "The current post in the loop" and can choose it, and save.
It is described here:
https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/

If you do not see that option it means you do not have Types installed.

#411726

Thx that did the trick. There are "no items found" for a entry without a "Business card" image, how do I hide an entry with a "null" value?

Your help has been invaluable!

#411952

When "No Items Found" is shown on your Screen it means, ther is no Post at all that matches your criteria.

It is not due to no Image, as this is only a Field of the Post.
If there would be a Post, but no Image for it, you would simply see a white output.

What you can do, is customize the Text in the Views loop part that is included within

[wpv-no-items-found]
  <strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
[/wpv-no-items-found]

Does that help?

#412004

Hi Beda,

That string was in my code. I think the issue is the fact that we do have a nested view situation. There is no nested view and that is the reason it shows NO items found. Is there a way to exclude the parent entry if there is no nested view to show? If i can explain a bit. The advertiser (parent) has a classified add (child)(nested view) is there are no classified add for the parent i don't want to see any entry for the advertiser. This is exactly the same setup as for the advertiser and business card setup as above. So what happens here will be applicable to the business card also when correctly setup.

Thx

#412016

You can not check a Child post from a Parent Post (or, from a parent View)

For that you need a Custom code which I added a while ago to our DOC:
https://toolset.com/documentation/user-guides/many-to-many-post-relationship/ > Displaying Many-to-Many Relationship Using Types PHP API > Below, there is an example on how to create a shortCode that returns all children posts IDs, which is useful to check if a post has child posts, inside a Views Loop.

#415025

HI Beda,

I looked through the example you gave me. It makes sense, although i am not really a php professional the structure makes sense. I would just like to recap and make sure I am not missing something.

The function bit of the code goes in my theme's function php edit screen. (using dynamik.) The

//It will query all child posts of the current event, that are appearance type
$child_posts = types_child_posts('appearance');
foreach ($child_posts as $child_post) {
    $band_id = wpcf_pr_post_get_belongs($child_post->ID, 'band');
 
    //You can also use WP Native API get_post_meta to get the parent post ID
    //as it is stored in a hidden custom field _wpcf_belongs_post-type-slug_id
    //$band_id = get_post_meta($child_post->ID, '_wpcf_belongs_band_id', true);
 
    $band = get_post($band_id);
    echo $band->post_title;
}

goes in the views of the advertisers loop output editor?

where do I put the evaluation code ?
Obviously i do replace "band " with "advertisers" and "Appearance" with the appropriate child slug name.

#415031

I think you look a the wrong code.

The sample I meant is at the very bottom of that page:

==> Below, there is an example on how to create a shortCode that returns all children posts IDs, which is useful to check if a post has child posts, inside a Views Loop.

function child_posts_exist_func( $atts ){
    $child_posts = types_child_posts('child-post-type-slug');
    if ($child_posts) {
        return 1;
    } else {
        return 0;
    }
}
add_shortcode( 'has-child-posts', 'child_posts_exist_func' );

Then, you can evaluate like this:

[wpv-conditional if="( '[has-child-posts]' eq '0' )"]
    You display things if does NOT have child posts
[/wpv-conditional]
 
[wpv-conditional if="( '[has-child-posts]' eq '1' )"]
    You display things if DOES have child posts
[/wpv-conditional]

As you see that is a ready to go solution, it also explains where and how to use it
You will need to adapt it to your Slugs (post type)

It will help you check if a Child Exists for a Parent in the View loop.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.