Navigation überspringen

[Gelöst] access to types using slug

This support ticket is created vor 4 Jahren, 2 Monaten. 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Dieses Thema enthält 5 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Luo Yang vor 4 Jahren, 2 Monaten.

Assistiert von: Luo Yang.

Author
Artikel
#1815319

Tell us what you are trying to do?
to access to my custom field using post slug but not item id.
I use [types field='some_types field' item='157'][/types] but want something like this
[types field='some_types field' POSTSLUG='post_slug'][/types]

Is there any documentation that you are following?
https://toolset.com/documentation/customizing-sites-using-php/functions/
https://toolset.com/documentation/user-guides/views-shortcodes/item-attribute/
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/
https://toolset.com/forums/topic/accessing-posts-by-slug-instead-of-post-id/
https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/
https://toolset.com/forums/topic/why-is-toolset-so-slow/

Is there a similar example that we can see?

What is the link to your site?

#1815993

Hello,

There isn't such kind of built-in feature within Toolset, you might consider custom codes, for example:
1) Create a custom shortcode with custom PHP function:
https://developer.wordpress.org/reference/functions/add_shortcode/

2) In this PHP function, get the post ID using post slug:
https://stackoverflow.com/questions/14979837/wordpress-query-single-post-by-slug

3) Then use above post ID to get the custom field value:
https://developer.wordpress.org/reference/functions/get_post_meta/

See above document, the WP function get_post_meta() is using post ID to retrieve custom fields.

#1821425

I was thinking that for the long story of Toolset this is not the first time when such question appears. I am not a programmer. So maybe it is possible to receive the code from support team?

#1821721

According to our support policy, we don't provide the custom codes support:
https://toolset.com/toolset-support-policy/

If you need more assistance for it, please provide a test site with the same problem also point out the problem post URL, I can setup a demo for you. Private message box enabled.

#1824421

Yes. I still need help. I create several tickets and receive 100% ZERO help. You dont need any my website. I did describe my problem. You and you friend in enother topic just allways tell me there is no problem or give me access. And no help back. I dont feel that i should wast my time creating some useless websites just because you pretend not to understand. There are huge amount of other topics where users resive snippets of code for help to users.
Your help is useless. I still have time to recive my money back if you cant help me.

#1824465

Please check our support policy as I mentioned above:
https://toolset.com/toolset-support-policy/
We cannot produce custom code solutions for you.

Since you are asking for some not-built-in feature, so it requires custom codes, and for different website, and different settings, the custom codes is different, and I have provide detail steps and documents in my first answer:
https://toolset.com/forums/topic/access-to-types-using-slug/#post-1815993

Here is an example:
1) Add below custom codes into your theme file "functions.php"

add_shortcode('get_field_by_postslug', function($atts, $content){
    $atts = shortcode_atts( array(
        'name' => '',
        'field' => '', // title, alt or id return
    ), $atts);
	$args = array(
		'name'        => $atts['name'],
		'post_type'   => 'post', // here replace with your custom post type slug
		'post_status' => 'publish',
		'numberposts' => 1,
		'fields'	=> 'ids'
	);
	$posts = get_posts($args);
	$res = '';
	if(isset($posts[0]) && is_numeric($posts[0])){
		$res = get_post_meta($posts[0], 'wpcf-' . $atts['field'], true);
	}
	return $res;
});

You will need to customize above codes according to your website settings.

2) Use above shortcode like this:
[get_field_by_postslug name="my-post-slug" field="my-field-slug"]

For your reference.