- This topic has 29 replies, 2 voices, and was last updated 3 years, 3 months ago by
David.
-
AuthorPosts
-
March 2, 2023 at 6:46 am #2552690
David
StaffCustomer SupportLet us know!
March 9, 2023 at 4:31 am #2561333nudnavda
Hi David,
sorry for the delay.
Had to arrange a few things first…I found a way to make local testing environment (via Wamp).
And tested the code you provided for the button with linked titles to pages.
Alas, the shortcode does not work, one way or another.I made a few test-pages (category: test) so you can see what’s going on:
https://dharmoebe.nl/test-overview/
Please let me know if I can do anything to assist you further.Thanks!
March 9, 2023 at 5:02 am #2561365David
StaffCustomer SupportSo that category has a slug of
testso the shortcode should be:[category_posts category_slug="test"]Does that work?
March 9, 2023 at 6:08 am #2561442nudnavda
That’s the slug i used.
But does not work.March 9, 2023 at 8:04 am #2561750David
StaffCustomer SupportDoes it work if you add it to the page content ?
March 9, 2023 at 8:25 am #2561778nudnavda
No, if you click test-1 you’ll see the result:
https://dharmoebe.nl/test-1/March 9, 2023 at 8:48 am #2561811David
StaffCustomer SupportHmm… i tested it on 3 dev sites and all 3 worked without any issues.
Do any shortcodes work ? Try this snippet:
add_shortcode( 'hello', function() { ob_start(); // Start your PHP below echo 'hello'; // End your PHP above return ob_get_clean(); } );the shortcode is
[hello]and it simply prints outhelloMarch 10, 2023 at 2:10 am #2562601nudnavda
Yes – your “hello” shortcode work.
See test-1 link.March 11, 2023 at 2:54 am #2563810nudnavda
Maybe some relevant info, David: I use the plugins ‘Post Type Switcher’ (to transform older single posts in pages where needed) and ‘Add Categories to Pages’ (to organize pages according to categories).
March 11, 2023 at 7:22 am #2563985David
StaffCustomer SupportHmmm…. it could be either of those plugins that are messing with the way terms are output.
Unfortunately i can’t replicate the issue locally, i tested the code on 3 dev sites and each of them it works as expected.You may need to look for a plugin.
March 12, 2023 at 1:44 am #2564640nudnavda
Yes, I understand.
Appreciate the support you’ve given.March 12, 2023 at 3:44 am #2564698nudnavda
I have one question that might help me: how have you “tested the code on 3 dev sites”?
You probably did not use any plugin to add a category to the pages?March 12, 2023 at 7:33 am #2564870David
StaffCustomer SupportOne last attempt.
Try this:function display_post_links_select_box( $atts ) { $output = ''; // Set up the shortcode attributes $atts = shortcode_atts( array( 'category_slug' => '', ), $atts ); // Get the current category ID, or the ID of the specified category slug if ( $atts['category_slug'] ) { $category = get_category_by_slug( $atts['category_slug'] ); $category_id = $category->term_id; } else { $category = get_queried_object(); $category_id = $category->term_id; } // Set up the query arguments to get posts in the current or specified category $args = array( 'posts_per_page' => -1, 'post_type' => 'page', 'post_status' => 'publish', 'orderby' => 'title', 'order' => 'ASC', 'category__in' => array( $category_id ), ); $query = new WP_Query( $args ); if ( $query->have_posts() ) { $output .= '<select name="post_links" onchange="location = this.value;">'; while ( $query->have_posts() ) { $query->the_post(); $output .= '<option value="' . get_permalink() . '">' . get_the_title() . '</option>'; } $output .= '</select>'; wp_reset_postdata(); } return $output; } add_shortcode( 'category_posts', 'display_post_links_select_box' );March 13, 2023 at 1:51 am #2565614nudnavda
I’m sorry this is creating a bit of a hassle now, David.
The latest code didn’t change the output.
So maybe working with tags instead of categories will offer a solution.
We’ll see.Thanks a lot, anyway! 🍺
March 13, 2023 at 5:18 am #2565827David
StaffCustomer SupportSorry i couldn’t be of much more help 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.