How to insert this php code via Function or PHP code actions

Help! What is the correct way of inserting this via Function / PHP code actions:

<?php if (!empty($url)) {?>><?php }?>

i understand that it should not contain <?php> tags, but what parts to remove? :sweat_smile:

if i put it manually, it will be overwritten on next export

thank you very much

i saw that my question was jumped over :slight_smile: sorry if i asked wrong or basic question…i’m new and i could really use some help. pinegrow looks great, and i want to move from webflow, but i also want to be sure that is right tool for me :slight_smile:

if it is not possible via PHP Code & Functions is there any other way to put this code (except writing it directly to file and overwiting on every export)

if i strip php tags i get something like this this:

if (!empty($url)) { > }

and of course it doesn’t work after export. What am I doing wrong?

please and thank you :slight_smile:

Come on, it’s summer, the :sun_with_face: is shining and rest assured that your message has not been purposely ignored.

If this is a condition you wish to integrate, there is an action for this:

1 Like

Hey Emmanuel, thank you very much :slight_smile: actually it’s raining here, so finally we can rest from the heat a little. Another thing popup, seems like there is no option for meta_query in The Loop:

‘meta_query’ => array {

Is there any workaround or i need to put it manually after every export?
:slight_smile: cheers and thank you again.

@fogseller to do that without having to manually edit after export:

#1 Use The Loop action (not Show Posts) and select “Args in own PHP block”.

This adds a PHP block where the query args are defined. PG changes this code whenever you change the The Loop action settings.

#2 To customize parameters, add your own PHP block AFTER the PHP block with query args and modify the args there.

Enjoy the rain! :slight_smile:


@matjaz worked like a charm! Thank you so so much! Pinegrow is BRILLIANT. B R I L L I A N T!!! WOOOOW! so happy, as you can tell… :grinning:


Hi @matjaz!

I’m currently working on a project and using the technique you outlined here but unfortunately one of the additional args I’ve added isn’t being used by the loop and I was hoping to get some clarification on how to set it up properly if possible.

For some background, I’m currently using a loop built with The Loop action to show a custom post type, and within that custom post type there is a date field named “event_date”. I would like the loop to only show posts that are after the current date and to list them in ascending order and also ordered by the the “event_date” field. (hopefully that makes sense)

In working up a solution for this I hand coded it first and then swapped the original Pinegrow generated loop’s args in the theme’s code to make sure it worked, and it did. From there I checked the “Args in own PHP block” and then added in the additional args that I couldn’t add through The Loop action in PHP blocks. Here is a code view of the Pinegrow generated args compared to what I originally hand coded.

On the front end the loop is correctly not showing any posts that are older than the current date but is unfortunately not ordering them by the “event_date” field in the CPT but rather by their creation date in WordPress (the default behavior).

If there was a way to add the CPT field into the “Order by” selector in the Order Parameters section in The Loop action I feel like it would work properly but unfortunately that’s not currently possible (or at least I can’t figure out how to make it work :wink:).

If you or @Emmanuel can shed some light on this and get me going in the right direction I’d really appreciate it.


Hi @chipriggs, to make it equivalent to your hand-coded example, the code in the purple circle should be:

$events_query_args['orderby'] = 'event_date';

@matjaz It works perfectly now, thanks so much for that! :pray: :pray:

1 Like


I’d like to add to this conversation for anybody who is using this method and wanting to apply it to a block thats using the @block: attribute for adding block controls in the editor for the user.

After you create the block and add the block attributes and also add the tags @block: in the places you want controls for the block, you need to use PG_Blocks::getAttributeForAction( $args, ‘your-attribute-id’

in the php block for the query like this:

$results_kw_args['tax_query'] = [
                        'relation' => 'AND',
                            'taxonomy' => 'msb_categories',
                            'field' => 'id',
                            'terms' => PG_Blocks::getAttributeForAction( $args, 'cat' ),
                            'taxonomy' => 'locations',
                            'field' => 'id',
                            'terms' => PG_Blocks::getAttributeForAction( $args, 'locations' ),


because if you use e.g ‘terms’ => ‘slug’, the query will not work. The values in the controls you made for the block will not be read and will return nothing. If you look in the php code block pinegrow generates, you will see thats how they are achieving the same thing. You simply have to apply it to your query code.

By doing the custom query above in a php block after the one generated by pinegrow I was able to make a gutenberg block where the user from the editor can choose location + service from custom taxonomies and display the results without having the custom query overridden when I save/export from pinegrow.

Block in action:

Hope this comes in handy.

(note: if you want to understand how to add gutenberb editor block controls, watch this video - 37. Product count attribute for the product list block - YouTube)