I am a beginner in PHP and I am using wordpress.
I am calling a post title inside a form(Gravity Forms) and use this line of code:
add_filter('gform_field_value_testtitle', create_function("", '$value = testing_title(); return $value;' ));
And what i need to make is a function that allows me to pre populate one of the gravity forms fields with the post title, and i do that like this:
function testing_title() {
global $wp_query;
while ($postid = $wp_query->post->ID) {
return $postid;
}
}
This returns the first post id and then it stops. So I have a list of posts but with this only the first post appears, and the id is inserted in the form.
How do I get the rest of them?
“return” leaves your function.
if you want to retrieve the rest of the data, you should store it in a variable (i.e. an array) and return that variable after the loop finished.