- This topic has 7 replies, 2 voices, and was last updated 2 years, 8 months ago by
David.
-
AuthorPosts
-
December 30, 2022 at 5:57 am #2477835
Stefan
Hey,
I have a question that is not part of the Generatepress core … but maybe you have a solution.
I would like to display different content on a page, depending on the url parameter.
Example
test.com/site/?example-1
Content: XYZtest.com/site/?example-2
Content: ABCIn the best case it would still be ACF Fields that are displayed.
Do you have any ideas how this could be implemented?
I have tried a few examples and found them on the search / Google, but nothing that has brought me completely further.
Thank you very much for your help!
If it is too far away from the “GP-Support” – feel free to delete the post 😉December 30, 2022 at 7:26 am #2477967David
StaffCustomer SupportHi there,
does this doc on ACF help?
https://support.advancedcustomfields.com/forums/topic/acf-field-value-from-query-string/
The basics here is its using:
$_GET['product_type']
to get theproduct_type
query param from the URL which it then uses to return the relevant field.December 30, 2022 at 8:08 am #2478117Stefan
Hey David,
thanks a lot for your help!
I have now built a version that works:add_filter( ‘the_content’, ‘my_quiz_filter’ );
function my_quiz_filter( $content ) {
if ( isset($_REQUEST[‘quiz-2’]) && is_single() && ‘quiz’ == get_post_type() )
{
$content = ‘<p>’ . get_field(‘quiz_losungs-story’) . ‘</p>’ . $content;
}if ( isset($_REQUEST[‘quiz-3’]) && is_single() && ‘quiz’ == get_post_type() )
{
$content = ‘<p>’ . get_field(‘quiz-story-longread’) . ‘</p>’ . $content;
}return $content;
}
But maybe you can help me with one last thing.
In this case the dynamic content is placed in “$content”.
Is it possible to you use one of the GP hooks like “generate_after_main_content”?December 30, 2022 at 8:15 am #2478129David
StaffCustomer SupportFor sure, instead of using the
the_content
filter hook. You can use an action hook eg.add_action( 'generate_after_main_content', 'my_quiz_filter' );
December 30, 2022 at 8:25 am #2478139Stefan
Okay, thanks … something I do wrong … or think wrong – in the variant it does not work unfortunately.
Do you have an idea?add_action ( 'generate_after_main_content', 'my_quiz_action' ); function my_quiz_action( $content ) { if ( isset($_REQUEST['quiz-2']) && is_single() && 'quiz' == get_post_type() ) { $generate_after_main_content = '<p>' . get_field('quiz_losungs-story') . '</p>' . $generate_after_main_content; } if ( isset($_REQUEST['quiz-3']) && is_single() && 'quiz' == get_post_type() ) { $generate_after_main_content = '<p>' . get_field('quiz-story-longread') . '</p>' . $generate_after_main_content; } return $generate_after_main_content; }
December 30, 2022 at 8:36 am #2478147David
StaffCustomer SupportJust print the content to the hook eg.
add_action ( 'generate_after_main_content', 'my_quiz_action' ); function my_quiz_action() { $field_value = ''; if ( !is_single() && 'quiz' != get_post_type() )) { return; // quit out if condition is not met } if ( isset($_REQUEST['quiz-2']) ) { $field_value = get_field('quiz_losungs-story'); } if ( isset($_REQUEST['quiz-3']) ) { $field_value = get_field('quiz-story-longread'); } printf('<p>%1$s</p>', $field_value ); }
December 30, 2022 at 8:40 am #2478151Stefan
Wow! This is fantastic! It works! Thank you very much. I’ll send the new year drink directly to you!
December 30, 2022 at 8:44 am #2478154David
StaffCustomer SupportYou’re welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.