Skip Navigation

[Gelöst] registering custom fields with soliloquy php

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.

Our next available supporter will start replying to tickets in about 5.40 hours from now. Thank you for your understanding.

This topic contains 23 Antworten, has 4 Stimmen.

Last updated by Marisa vor 6 Jahre, 6 Monate.

Assigned support staff: Adriano.

Author
Artikel
#297411

Waqas
Supporter

Languages: Englisch (English )

Timezone: Asia/Karachi (GMT+05:00)

This is Waqas here, on behalf of Mr. Adriano. He's on a holiday and will join back tomorrow.

He will follow up with you, as soon as he returns. Thank you for your cooperation and patience.

Have a nice day.

#297845

Hello Marisa,

I fully understand your point. As you can see "By default, custom meta field queries are not part of the...", he said custom meta field queries, it's filtering. The only purpose of soliloquy_fc_query_args is to extend the query to add filter that by anything, including custom fields, but only filtering! I know that because we have a way to extend the View's query as well, also with a WP filter.

I've watched the vide about that plugin, as I could see there is no way to se custom fields in the slides (not only Types custom fields, but any kind of custom field). This plugins seems to be not compatible with WordPress custom fields, not for adding in the query, but for displaying custom field data in the slider.

You are right about our sliders, we are working hard to make them responsive. I'm sorry about that.

The only suggestion I could tell you is to contact the author of your plugin and see if there is some way to add custom fields in the slider and I'll be more than happy in helping you with that.

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

Regards,

Adriano Ferreira

#298105

I'm so happy I feel understood with what I'm asking. Thank you for your kind reply. Soliloquy has pointed me to a new function because they also finally understand I am trying to display, not create or filter by, custom fields. However, it's not working. It is making a lot more sense though.

Here is the new code from here: hidden link

<?php
/**
* Plugin Name: Soliloquy - Featured Content - Display Custom Fields
* Plugin URI: <em><u>hidden link</u></em>
* Version: 1.0
* Author: Tim Carr
* Author URI: <em><u>hidden link</u></em>
* Description: Displays Custom Fields on Featured Content Slides
*/

/**
 * Append the Post's Custom Field values onto the end of the content
 *
 * @param string $pcontent Post Content
 * @param WP_Post $post WordPress Post
 * @param array $data Slider Data
 * @return string $pcontent;
 */
function soliloquy_featured_content_display_custom_fields( $pcontent, $post, $data ) {

	// Get custom field values
	// If you're using ACF, you could use get_field( 'wpcf-case-story-text', $post->ID )
	$text = get_post_meta( $post->ID, 'wpcf-case-story-text', true );
	$image = get_post_meta( $post->ID, 'wpcf-case-story-image', true );

	// Append custom field values to the existing content
	// Amend as necessary
	$pcontent .= $text . $image;

	return $pcontent;

}
add_filter( 'soliloquy_fc_post_content', 'soliloquy_featured_content_display_custom_fields', 10, 3 );

I tried changing the get_post_meta to "types_render_field" as well but it still had no effect.

Thanks again.

Also I am looking forward to the swipe enabled and responsive thumbnailed sliders.

Here is the test slider page:
hidden link

#298390

I'm also so glad I could help you to ask the right question to the plugin's author. Per the page's code of the plugin, I feel they added that doc page because of you, look the field names "wpcf-case-story-text" 🙂

The code looks good, you are using the right custom field name. I'm not sure, although, about where to insert the code:

"To include a Post’s Custom Fields in the content of your Featured Content slider, add the following code to a new file at wp-content/plugin/soliloquy-featured-content-display-custom-fields.php"

Could you clarify with them? Should you insert the code directly in the filed "soliloquy-featured-content-display-custom-fields.php" or in the functions.php?

#302681

I did follow up with them and am waiting for a reply.

Could you let me know if you think the code is correct even though I am waiting for where to put it?


/**
* Plugin Name: Soliloquy - Featured Content - Display Custom Fields
* Plugin URI: <em><u>hidden link</u></em>
* Version: 1.0
* Author: Tim Carr
* Author URI: <em><u>hidden link</u></em>
* Description: Displays Custom Fields on Featured Content Slides
*/

/**
 * Append the Post's Custom Field values onto the end of the content
 *
 * @param string $pcontent Post Content
 * @param WP_Post $post WordPress Post
 * @param array $data Slider Data
 * @return string $pcontent;
 */
function soliloquy_featured_content_display_custom_fields( $pcontent, $post, $data ) {

	// Get custom field values
	// If you're using ACF, you could use get_field( 'wpcf-case-story-text', $post->ID )
	$text = types_render_field( $post->ID, 'wpcf-case-story-text', true );
	$image = types_render_field( $post->ID, 'wpcf-case-story-image', true );

	// Append custom field values to the existing content
	// Amend as necessary
	$pcontent .= $text . $image;

	return $pcontent;

}
add_filter( 'soliloquy_fc_post_content', 'soliloquy_featured_content_display_custom_fields', 10, 3 );
#303532

Your code looks good. You should add it in functions.php.

#303552

OK, that's what I thought. I did that, it did nothing.

Since Soliloquy has no answers as to why, and you have done everything possible to help, I came up with a different solution.

I am using Shortcodes Ultimate instead for the slider functionality, combined with Types and Views.

It is swipe enabled on mobile, which is really the priority here, along with the ability to build sliders from custom content.

I used the Shortcodes Ultimate Extras Add-on and used the Content Slider Shortcode:

The result looks great in desktop and mobile and is swipe enabled:
hidden link

(it has nothing to do with soliloquy even though that's in the slug).

My View settings are as follows:

I checked case stories.

My loop output looks like this:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
          [su_content_slider arrows="yes" pages="no"]<wpv-loop>[wpv-post-body view_template="SU Single"]</wpv-loop> [/su_content_slider]
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		[wpml-string context="wpv-views"]<strong>No items found</strong>[/wpml-string]
	[/wpv-no-items-found]
[wpv-layout-end]

My content template looks like this:


[su_content_slide]
[types field="case-story-image" size="full" align="none"][/types]<div class="case-story-text">
  <h1>[wpv-post-title]</h1><p class="story">[wpv-trim-long words="20"][types field="case-story-text" output="raw"][/types][/wpv-trim-long]</p></div>
[/su_content_slide] 

My css looks like this:

 .case-story-text {
      position:absolute;
      bottom:10%;
      right:20px;
      background-color:rgba(0,0,0,.5);
      display:block;
      width:30%;
      padding:10px 20px 0;
    }
    p.story {
      color:#fff;
      font-size:18px;
    }
	h1 {
      color:#fff;
    }
@media screen and (max-width:800px) {
  
      .case-story-text {
          position:relative;
          background-color:#fff;
          margin-top:15px;
          width:100%;
          float:left;
      }
      p.story, h1{
          color:#6e6e6e;
      }
}

I really hope this helps someone else. Combining types and views with SU is amazingly powerful. The code for the above using only Content Slider from SU would have been many more lines without Types and Views to query the custom post types and let me have granular control over the content template style (the slides).

And most valuable, due to the Views query loop, I can make a change in one place and it changes all slides. Also the client or team can add a case story and it will magically appear in the slide, why I love to use Views in the first place.

#303850

Really awesome, thank you for sharing your workaround with us.

#303870

You're welcome! Thanks for hanging in there with me.

I am now building accordions, tabs, all kinds of things with the same method. It's amazing. Types' compatibility with other plugins and its ability to query anything is marvelous.

Marisa