Skip Navigation

[Cerrado] Problems to show parent fields into posts with a view

This support ticket is created hace 9 años, 7 meses. 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
- 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 -
- - - - - - -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 16 respuestas, has 2 mensajes.

Last updated by Adriano hace 9 años, 5 meses.

Assisted by: Adriano.



I want to show some parent fields into desired posts with a view. I read but in all posts I insert my view I always get the same product.

I have the next structure.

Three Custom Types (Empresas, Smartphones and Tablets)

Empresas -> Smartphones -> Posts
-> Tablets - > Posts

Smartphones and Tablets are childs of Empresas

My view is called "Productos Relacionados" I attached you an image with the settings. And the layout code is

	<!-- wpv-loop-start -->
  <div id="related-product">
    <h3>Producto Relacionado</h3>
          <div class="producto-relacionado">
            [types field="abn_foto" size="thumbnail" id="$Smartphones" id="$Tablets"][/types]
            <div class="custom-fields">
              [wpv-post-link id="$Smartphones" id="$Tablets"]
              <p><strong>SO</strong> [types field="abn_android_so" id="$Smartphones" id="$Tablets"][/types]</p>
              <p><strong>Precio</strong> [types field="abn_android_precio" id="$Smartphones" id="$Tablets"][/types]</p>
	<!-- wpv-loop-end -->

Well, I always get the same result in all posts, for instance, in hidden link the related product "Producto Relacionado" had to be Samsung Galaxy S5 and not LG Flex (attached image) that happens in every post with the view I always obtain LD Flex which is the latest product created in the blog.

Where is the problem?



Dear Miguel,

You need to add the filter "Post relationship - Post is a child of" to make it working well.


Thanks Adriano,

I have added the query filter but now the view in the post has vanished

hidden link


Dear Miguel,

I will enable the private information section on this ticket, so please provide credentials of the site. I will need that to debug this issue for you.



credentials are


Tell me if you need something more.



Dear Miguel,

There is a htaccess protection, could you provide it too?


Oh, I'm so sorry I forgot it


If you are banned give me your ip and we will unblock it.

Best regards


Dear Miguel,

I need to see the Related Product section, I think you disabled it. Can you enable it again and explain how to see the issue?


Sorry Adriano, I was on holidays.

Here the view hidden link

and here a post with the view inserted hidden link

I have removed query filter "is child of" and it is visible again.

Do you need anything more?



Dear Miguel,

First you need to create a relation between Entradas post type with the desired post type. The example you show me is an "Entrada", what posts are related with it? hidden link

So then you can use the php code below to add some arguments on your view:

add_filter( 'wpv_filter_query', 'posts_same_parent_func', 10, 3 );
function posts_same_parent_func($query, $view_settings, $views_ID){
    if($views_ID == 123)
        $query['meta_key'] = '_wpcf_belongs_empresas_id';
        $query['meta_value'] = get_post_meta($post->ID, '_wpcf_belongs_empresas_id', true);
    return $query;

Of course you need to replace 123 with the ID of the View you want to work. Also you should replace "empresas" with the ID of the parent post type.

When using Types posts relationships, we store the parent of a given type in a field _wpcf_belongs_{parent-slug}_id. Assume we are displaying a Car post type that usually has a parent Maker post type. Each Car will store its Maker id in the field _wpcf_belongs_maker_id.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.


Hi again Adriano and sorry for the delay. We have been testing the code you gave me and doing other actions, but the problem is still there.

After Reading your last answer I would like to explain you the structure of the relationships between our types again.

First at all, Type "Entradas" is the default WordPress "Posts" Entradas is only the translation into spanish

Therefore, we have a Parent called Empresas with two childs Smartphones and Tablets. Each child type Smartphones and Tablets have assigned as child Posts = Entradas.

In the settings of each Type we have setting the relationships (Fig 1 attached) and when we write a post, talking for example about a Smartphone we relate this post with his parent, e.g. HTC ONE M8 (Fig 2 attached)

Am I doing it right?

At last, what we want to get is to show information about parent in this selected posts inserting the "Productos Relacinados" view.

Perhaps I am wrong and there are another easier solution. What I want is "as simple as" show parent information into Posts.


Dear Miguel,

I think the configuration of your relationship is not correct. The correct one should be:

Smartphones: Its parent should be "Empresas" and Children you should let blank
Tablets: Its parent should be "Empresas" and Children you should let blank

If you still can not configure it properly I can help you, the private area is still enabled, you could safely share credentials of your site by there.


Hi again,

I have done the changes you suggested me but I can't get it work

I let you the access to wp-admin and remember we have .htaccess protection actualidadblog actualidadblog

If you can let it working I will learn how it is done for other projects.

Thanks in advance


Dear Miguel,

The configuration of the post types are fine. The thing is you will need to customize the query of the View to achieve what you want, which is to list all posts of the same parent than the current displayed. So the code below should does this for you, please add in functions.php of the current theme:

add_filter('wpv_filter_query', 'same_parent_func', 10, 2);
function same_parent_func($query, $settings) {
    if($settings['view_id'] = 123)
        $query['meta_query'][] = array(
        'key' => '_wpcf_belongs_post_id',
        'value' => get_post_meta(get_the_ID(), '_wpcf_belongs_post_id', true),
        'compare' => '='
    return $query;

You need to replace 123 with the ID of the view, also you will need to replace "_wpcf_belongs_post_id" with the correct post parent slug, I think it is "_wpcf_belongs_empresa_id".

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.



we have done the changes you suggested but we have the same problem, the view return always a wrong result

El debate ‘[Cerrado] Problems to show parent fields into posts with a view’ está cerrado y no admite más respuestas.