Skip Navigation

[Gelöst] Using PHP to attach Hazard Product(CPT) posts to the Major Hazard(CPT) parent.

This support ticket is created vor 3 Jahre, 8 Monate. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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

Supporter timezone: America/Jamaica (GMT-05:00)

Dieses Thema enthält 35 Antworten, hat 3 Stimmen.

Zuletzt aktualisiert von Luigi Bella vor 3 Jahre, 6 Monate.

Assistiert von: Shane.

Author
Artikel
#1809167

Hi Shane,

Yes, that's correct. Looking forward to your solution. Would it be beneficial to provide you with a zoom link if you had any questions? That way I can have an immediate response for you.

Thanks

#1810557

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Luigi,

I've gotten this to work now. Have a look at the post here.
versteckter Link

This is the view that i've setup to run the query.
versteckter Link

Please let me know if this helps.
Thanks,
Shane

#1810595

Hi Shane,

That seems to work, except we already have existing views set in place for the hazard products. Is there a way to incorporate what you've done into our existing views. I've done a quick recording about the views and the Major Hazard page:
versteckter Link.
versteckter Link

-The shortcode for the view is located in a Divi builder template so it won't require us to insert that shortcode into the post body.

Just wanted to note that everything from the Test Hazard Products view will be transferred over to the Hazard Products view, which we plan to use for future pages.

Thank you

#1810599

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Luigi,

Yes there is as you can see there is a shortcode that was added to my test view.

All you need to do is to place this shortcode your existing view as well as setup the query filters from my test view in your actual view.

I called my test view in the post body with a shortcode parameter to pass the current hazard ID into the view.

This way it will filter for all the products with the same hazard id which will allow the custom shortcode to update the posts and setup the relationship.

Please let me know if this is clear or if further clarification is needed.

Thanks,
Shane

#1810621

Hi Shane,

It works in connecting the posts. But hazard products (child posts) are no longer displayed in the view. versteckter Link
What else can I try? Are you able to check that I did everything per your recommendation?

Thank you

#1811331

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Luigi,

Thanks for the video, I see where you have the view shortcode you are still using the static value for the hazard parameter.

You will need to add it like this below to get the hazard ID dynamically.

[wpv-view name='my-view' hazard="[types field='hazard-id'][/types]"]

Please try this and let me know the results.
Thanks,
Shane

#1811583

Hi Shane,

I changed the static value to a dynamic value for the hazard parameter. We have our view shortcode in a Divi Theme Template which I added the dynamic hazard parameter. That didn't work in connecting the posts. I've tried placing your shortcode in the Divi Theme Template which connects the posts but it's pulling other posts that don't have the same hazard parameter.

I've tried using my view shortcode directly in the post body and that hasn't worked either. I'm noticing that the connecting of posts only works when I use your view and with it connected, it's still not displaying on the frontend for our view.

versteckter Link

Thank you

#1812503

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Luigi,

After the posts are connected you will need to refresh the page for your view to show up.

What you can do is to use my view to connect the posts. For my view you can actually delete the shortcodes that is used to display the data as this was just there as a test.

So you can add my view to your page but then you need to refresh the page after its first load in order to see the changes in your view.

I believe your view should just be pulling the child posts correct ? However from what I see here in the link below its not setup to pull the child posts through a post relationship.
versteckter Link

Please let me know.
Thanks,
Shane

#1812851
Screen Shot 2020-10-14 at 10.54.39 AM.png

Hi Shane,

I refreshed the page multiple times and did not get the view to show up.

The view initially was set up with the relationship filter shown below. I found that removing it allowed for the posts to be connected and displayed. I will re-instate the relationship filter to see if it will continue to connect and display the posts.

Thanks.

#1812889

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Luigi,

Your custom code here


add_filter( 'wpv_filter_query', 'func_filtre_dateincident', 10, 3 );
function func_filtre_dateincident( $query, $settings, $views_id ) {
       
    if($views_id == 251655){
       
     if(!empty($query['meta_query'])){ 
       foreach((array)$query['meta_query'] as $k=>$v):
            if(isset($v['key']) and $v['key']=='wpcf-dated'){
                   
 
                $values = explode(",",$v['value']);
                 
                if(!empty($values)){
                     
                    unset($query['meta_query'][$k]);
                      $dvalue[] = $values[0];
                      $dvalue[]  = $values[0] + 24 * 60 * 60;
                  
                        $query['meta_query'][$k]['key'] = 'wpcf-dated';
                        $query['meta_query'][$k]['type'] = 'NUMERIC';
                        $query['meta_query'][$k]['compare'] = 'between';
                        $query['meta_query'][$k]['value'] =  join(",",$dvalue);
                }
                   
                   
            }
        endforeach;
     }        
      
    return $query;
    }
}

This is interfering with the normal operation of the view causing it to produce the incorrect result. This is causing my view here to give the incorrect results.
versteckter Link

Whenever that code is active the view doesn't produce a result. So I would suggest doing a review of this code.

Thanks,
Shane

#1812945

Hi Shane,

Even with the custom code removed, your code doesn't work with a relationship filter.
When I remove the relationship filter, your code works in connecting the posts except then the datepicker no longer works. That custom code was provided by Minesh to ensure that the datepicker works.

I am noticing that your code and Minesh's custom code works without the relationship filter. What other code changes can you recommend for the datepicker to work?

versteckter Link

Thanks

#1812961

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Luigi,

What i'm saying is that for this you will need to use 2 views.

The first view i.e the one I made will just be used to connect the posts, so you can remove all the output shortcodes from the content template and leave the custom shortcode I made.

The view that you made you can continue to use it as you normally do, remove any filter that is related to the customization from my view.

This way your view will display the updated information after the view that i've created connects the posts.

Please let me know if you understand this approach. The main issue is that you won't be able to combine all your current filters plus the filters that I use .

My view needs to only have the filter by the hazard ID which will allow you to connect all the posts with the same hazard ID.

You view will take care of all the other filters after the posts have been connected.

Thanks,
Shane

#1813089

Hi Shane,

I understand the approach you mentioned. I have tried using the views per your approach but it is interfering with the formatting of the child posts if used separately from my view. Could you make the next response private so I can share a zoom link to show you what exactly is happening?

Thanks

#1813949

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Luigi,

We only do support via the forums or our Live chat.

What you can do is to record a short clip demonstrating what happens and I will see how best I can assist in resolve it.

Thanks,
Shane

#1814345

Hi Shane,

Your view requires that I apply the same formatting as my current view so it defeats the purpose of using them separately.

Your custom shortcode works in my view if the relationship filter is removed. Which leaves the datepicker issue. If I don't have that custom code active, the datepicker won't work. What do you recommend I add to your connect code to ensure the datepicker works?

Thank you

Dieses Ticket ist jetzt geschlossen. Wenn Sie ein Toolset Kunde sind und Hilfe benötigen, eröffnen Sie bitte ein neues Support-Ticket.