0

I have got this working code using wordpress and advanced custom fields:

$include = get_pages('include=1575');
$title = apply_filters('the_title',$include[0]->post_title);
$content = apply_filters('the_content',$include[0]->post_content);

I want to create a var replacing the post_id in include=1575. I get this var using:

$site_id = the_field('id_grundgedanke'); // output exp: 1575

How I can I combine these? I have tried the following:

 $site_id = the_field('id_grundgedanke');
 $include = get_pages('include=' . $site_id);
 $title = apply_filters('the_title',$include[0]->post_title);
 $content = apply_filters('the_content',$include[0]->post_content);

Which does not work.

0

1 Answer 1

2

Use get_field() instead of the_field().

get_field() - Returns the value of the specified field.

the_field() - Displays the value of the specified field. This function is the same as echo get_field($field_name);

Corrected code:

 $site_id = get_field('id_grundgedanke'); // use get_field
 $include = get_pages("include=" . $site_id);
 $title = apply_filters('the_title',$include[0]->post_title);
 $content = apply_filters('the_content',$include[0]->post_content);
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks a lot! I understand this :P
there is one mistake, "include=$site_id" does not work. I have suggested the necessary edit!
@MarianRick: It should work. don't know the reason. anyway thanks for your edit. :-)
Receiving the following in debug modus: Notice: Undefined offset: 0 in /wp-content/themes/aupair2000/page_cover-site.php on line 73 Notice: Trying to get property of non-object in /wp-content/themes/aupair2000/page_cover-site.php on line 73 Notice: Undefined offset: 0 in /wp-content/themes/aupair2000/page_cover-site.php on line 74 Notice: Trying to get property of non-object in /wp-content/themes/aupair2000/page_cover-site.php on line 74
@MarianRick: You should print $include and check what data you are receiving. Write echo '<pre>'; print_r($include);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.