Fma965
(Fma965)
May 13, 2022, 10:14pm
1
I seen this but it seems it’s fixed?
I’m having trouble getting WP Discourse Plugin Tips and Tricks to work in terms of restricting available categories for a custom post type.
Discourse plugin settings include the custom post type in question (as well as other post types) and a global default Discourse category has been selected. This global setting works: the specified category is the default and you can select to publish to a different Discourse category on a case by case basis.
For this specific custom post type, I wish to re…
<?php
add_filter( 'wp_discourse_publish_categories', 'my_namespace_filter_categories', 10, 2 );
function my_namespace_filter_categories( $categories, $post ) {
if ( 'asbuilt-db' === get_post_type( $post ) ) {
$output = [];
foreach ( $categories as $category ) {
if ( 'Databases' === $category['name']) {
$output[] = $category;
}
}
return $output;
} else if ( 'applications' === get_post_type( $post ) ) {
$output = [];
foreach ( $categories as $category ) {
if ( 'Applications' === $category['name']) {
$output[] = $category;
}
}
return $output;
}
return $categories;
}
Asbuilt DB part works
Applications part with new layout does not
angus
(Angus McLeod)
May 16, 2022, 4:39pm
2
Hey there @Fma965 ,
Could you just confirm for me that your custom post types have show_in_rest
enabled?
See the example here
Adjusting the comments_number sync period for WordPress archive pages
To get the correct number of Discourse comments for a post, the plugin needs to periodically make an HTTP request to Discourse to get the current comments number. On single pages this period is set to be no more often than every 10 minutes. For archive pages the period is set to no more than once every 24 hours. The reason for this is to avoid making multiple request to Discourse every time an archive page is accessed.
If …
See also
angus
(Angus McLeod)
May 16, 2022, 5:03pm
4
The filter should be working (I just tested it). Could you please try a simpler filter to see if it’s the filter or something else?
add_filter( 'wp_discourse_publish_categories', 'my_namespace_filter_categories', 10, 2 );
function my_namespace_filter_categories( $categories, $post ) {
return array_filter( $categories , function( $c ) { return $c['name'] === 'Databases'; });
}
1 Like
Fma965
(Fma965)
May 16, 2022, 5:09pm
5
Thanks, with this i managed to figure out what the issue is.
for reference i am using Advanced Scripts and if i set “location” to administrator area only it doesn’t work, it seems the code needs to run on either “everywhere” or “Front-end”
But the non blocks layout seems to work fine with Administration area, so i guess the Blocks interface is technically “front-end”
Problem solved thanks
EDIT: do you happen to know if this has been implemented? How to tag posts that are published from WordPress to Discourse - #4 by Fma965
angus
(Angus McLeod)
May 16, 2022, 5:16pm
6
Yup, because it’s consuming the REST API.
Fma965
(Fma965)
May 16, 2022, 5:22pm
7
Yeah that was my thought process, which is why I changed that after you mentioned REST and confirmed it was working on your end thanks again for you help.
1 Like
system
(system)
Closed
June 15, 2022, 5:23pm
8
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.