Skip Navigation

[Resolved] registering custom fields with soliloquy php

This support ticket is created 8 years, 1 month 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
- 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)

Tagged: 

This topic contains 23 replies, has 4 voices.

Last updated by Marisa 8 years ago.

Assigned support staff: Adriano.

Author
Posts
#295779

I am trying to:
Using this function in soliloquy here: hidden link (code below):

add_filter( 'soliloquy_fc_query_args', 'tgm_soliloquy_fc_meta_query', 10, 3 );
function tgm_soliloquy_fc_meta_query( $query_args, $id, $data ) {
    
    // If not the proper slider ID, return early (change 1234 to your specific slider ID).
    if ( '1234' !== $id ) return $query_args;
    
    $query_args['meta_query'] = array(
        array(
            /*
             * Your custom meta query goes here, something possibly like:
             *
             * 'key'     => 'color',
	     * 'value'   => 'blue',
	     * 'compare' => 'NOT LIKE'
	     *
	     * See http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters for more details.
             */
        )
    );
    
    return $query_args;
    
}

I'm simply trying to replace the queries inside the array with the proper calls to my custom fields, the urls of which are

case-story-text
case-story-image

both belonging to custom post type
case-story

I don't understand my custom fields in the context of key - blue, etc.

I tried the following:
'field_value' => 'case-story-image',
'field_value' => 'case-story-text',
'meta_value' => 'case-story-image',
'meta_value' => 'case-story-text',
'types_render_field' => 'case-story-image',
'types_render_field' => 'case-story-text',

to no avail.

What should I insert? What am I doing wrong?

#296066

Shane
Supporter

Languages: English (English )

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

Hi Marisa,

Thanks for contacting us.
In order to render the fields that were created using our types plugin you will need to follow the instructions here : https://toolset.com/documentation/user-guides/displaying-wordpress-custom-fields/#1

#296068

isn't that what I did when I called types_render_field?

That is the page I spent about 45 minutes studying.

Can you be more specific and tell me which part of the soliloquy code above I should replace and with what?

Thank you in advance.

#296077

Shane
Supporter

Languages: English (English )

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

Hi Marisa,

Normally with our custom field they get the prefix wpcf- appended to them.

What you can try doing is to is to append that prefix to the custom field slugs.
Eg. wpcf-case-story-image

Please try that and let me know.

Since this is a third party plugin that you are using to get our types field I cannot guarantee that it will work.

Thanks

#296084

Thank you.

I had to guess at what you meant since it wasn't a very specific answer.

Did you mean this?

/*custom field display for soliloquy */


add_filter( 'soliloquy_fc_query_args', 'tgm_soliloquy_fc_meta_query', 10, 3 );
function tgm_soliloquy_fc_meta_query( $query_args, $id, $data ) {
     
    // If not the proper slider ID, return early (change 1234 to your specific slider ID).
    if ( '1817' !== $id ) return $query_args;
     
    $query_args['meta_query'] = array(
        array(
      
            'types_render_field' => 'wpcf-case-story-image',
            'types_render_field' => 'wpcf-case-story-text',

            
        )
    );
     
    return $query_args;
     
}

or this perhaps?


/*custom field display for soliloquy */


add_filter( 'soliloquy_fc_query_args', 'tgm_soliloquy_fc_meta_query', 10, 3 );
function tgm_soliloquy_fc_meta_query( $query_args, $id, $data ) {
     
    // If not the proper slider ID, return early (change 1234 to your specific slider ID).
    if ( '1817' !== $id ) return $query_args;
     
    $query_args['meta_query'] = array(
        array(
      
            'field_value' => 'wpcf-case-story-image',
            'field_value' => 'wpcf-case-story-text',
            
        )
    );
     
    return $query_args;
     
}
#296085

Maybe the $query args meta query part should also be replaced??

#296149

Shane
Supporter

Languages: English (English )

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

Hi Marisa,

I went ahead and escalated this thread so that a higher level support staff can take a look at this.

They will be able to assist you better than I can.

Please be patient as they will be in touch with you shortly.

#296418

Hello Marisa,

You should add the Types prefix (wpcf) in custom fields created with Types:

key'  => 'wpcf-case-story-text'
key'  => 'wpcf-case-story-image'

Please let me know if you are satisfied with my reply and any other questions you may have.

Regards,

Adriano Ferreira

#296883

So my code looks like this:

/*custom field display for soliloquy */

add_filter( 'soliloquy_fc_query_args', 'tgm_soliloquy_fc_meta_query', 10, 3 );
function tgm_soliloquy_fc_meta_query( $query_args, $id, $data ) {
     
    // If not the proper slider ID, return early (change 1234 to your specific slider ID).
    if ( '1817' !== $id ) return $query_args;
     
    $query_args['meta_query'] = array(
        array(
                 'key'     => 'wpcf-case-story-text',
                 'key'     => 'wpcf-case-story-image',
                 'key'     => 'wpcf-case-story'
             
        )
    );
     
    return $query_args;
     
} 

But no dice.

I really would appreciate someone looking further into this.

#297150

Hello Marisa,

No, the code isn't right. Per my understanding, the aim of that filter is to build a query for a Slider, right? So, please let me know how you want this query, what kind of comparison do you want? For example, posts that wpcf-case-story-text is equal to "123". As soon as you informa the desired query, I'll build that for you.

#297190

That sounds promising, but I'm not 100% sure I understand what information I need to provide. I'll give it a try. Please let me know if I need to provide something else. Also wp-types already has a login which I can provide in a secure environment.

The custom post type slug is case-story
post_type=case-story

custom fields for case-story:
case-story-image
case-story-text

published posts id are:
1402
1397
1395
1300
1399
1298
I see no reason why you need the post id's but just in case I posted them here.

<b>I'm pretty sure the 1817 from the soliloquy example refers to the post id OF THE SLIDER (not the post id). </b> Their example says 1234. I've changed it to 1817 to reflect my slider id.

This is the code solioquy provids online in their docs to register my custom fields with their slider:
hidden link

Only problem is it's not working as I understand it.

I really appreciate your help.

Also, I keep rereading this sentence: For example, posts that wpcf-case-story-text is equal to "123". Are you sure that's exactly what you meant to say? Grammatically it's throwing me off so I don't know what it means. Apologies.

Marisa

#297193

To be clear, I am NOT trying to build a custom slider from scratch. I've done that a dozen times or more with Views. I really appreciate the features soliloquy has as it is a full-featured slider plugin. Soliloquy has one little function to call the custom fields in your custom post types so you can build a custom post type slider. Their function requires knowledge from Toolset that Soliloquy would not have (how to register custom fields built with Toolset).

That is the piece I'm missing.

The features soliloquy has that I am unable to use with Views are these:
mobile enabled swiping.
thumbnails that are fully responsive.

Even the wonderful thumbnail slider from Flex (downloaded from modules) does not have scalable thumbnails, and when you turn the thumbnails off and replace with next previous nav, all kinds of bad things happen, such as the swipe going away.

#297205

Something else that might be helpful:

If you examine the code on this slider you can see it's querying the custom post type but not the fields. 🙁

hidden link

(Also it's querying only the default wordpress field, the title, but even though it's showing in the inspect element it's not showing in the slider. I thought it was just a css issue at first but css doesn't fix it).

I am pursuing this same issue with soliloquy but they seem lost as to custom fields queried that are created by wp-types. That's why I am asking you.

Marisa

#297210

Hello Marisa,

I don't think you get the purpose of the soliloquy_fc_query_args action. It's just a way to extend the query of the featured posts. As you have custom fields defined with Types, you can edit the default query adding some evaluations for your custom fields.

For example, let's say you are displaying a list of featured Schools, but you also have a custom field called "wpcf-school-category" and you want to filter by it when displaying the featured posts. So you can add something like that:

add_filter( 'soliloquy_fc_query_args', 'tgm_soliloquy_fc_meta_query', 10, 3 );
function tgm_soliloquy_fc_meta_query( $query_args, $id, $data ) {
    
    // If not the proper slider ID, return early (change 1234 to your specific slider ID).
    if ( '1234' !== $id ) return $query_args;
    
    $query_args['meta_query'] = array(
        array(
             'key'     => 'wpcf-school-category',
	     'value'   => 'Elementary',
	     'compare' => '='
        )
    );
    
    return $query_args;
    
}

Your featured slider will contains only Schools that has "Elementary" stored in the "wpcf-school-category". Does that make sense?

#297217

Your description seems exactly my understanding of the function, but not really a helpful answer. I gave you all the fields so it would just be reassuring to see them in the code to know I am understanding how they fit in.

I'm not "filtering" by the custom fields. If it only does filtering, then it is indeed not the tool or code I need.

But if the function allows for "extending to extend the query" by including the custom fields in my query, then that is what I am attempting.

Since there is little description or commenting on this function, it's harsh to act as if I'm supposed to inherently know if I'm misunderstanding what it's supposed to do.

Take this line, for instance, "By default, custom meta field queries are not part of the Featured Content Addon interface. However, that doesn’t mean that you can’t do them."

That would lead one to believe that you can add custom fields to your query, as well as the custom post type.

Right now it only queries the custom post type but it acts as if the custom fields don't exist.

If the function soliloquy has provided has no intention of adding custom fields to the slider for display, then I would abandon it (that's what it sounds like though).

I would be happy to go back to building sliders with Views if they were swipe enabled on mobile. This is really important from a user perspective - swipe is much more mobile friendly than poking at next and previous nav arrows or searching for tiny thumbnails.

Marisa