michaelgoal
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Overwrite default post categoryDid you give up on this issue?
Its ok but though nice to know??Forum: Developing with WordPress
In reply to: Overwrite default post categoryhi again,
I have these tables and data with this post:
wp_posts (table)
ID: 353
post_status: public
post_type.post
———————————Wp_term_relationships (table)
object_id: 353
term_taxanomy_id: 1
term_order: 0
——————————–
wp_term_taxanomy (table)
term_taxanomy_id: 1
term_id: 1
taxanomy: categoryterm_taxanomy_id: 24 (another category)
term_id: 24
taxanomy: categoryterm_taxanomy_id: 25 (another category)
term_id: 25
taxanomy: category————————–
wp_terms (table)
term_id: 1
name: ikke-kategoriseret
slug: ikke-kategoriseretterm_id: 24
name: l?b
slug: loebterm_id: 25
name: rygestop
slug: rygestop
——————————-
It iscategory
isnt it ?Post with ID=53 should have term_taxanomy_id: 24 and then term_id:24 and name: l?b
but it just has default values like:
term_taxanomy_id: 1 and then term_id:1 and name: ikke-kategoriseretIs it before this if:
if (array_key_exists('vis', $_GET ) && '92'== $_GET['vis']) {
you would put an error_log ?
And what should i put into the error_log() braces ?
Or can i try to print something if its true ? and how ?Forum: Developing with WordPress
In reply to: Overwrite default post categoryYes i have post-new.php and the other calls that you mention.
In debug.log only error is:
Trying to get property ‘post_parent’ of non-object in /home/www/goaldigger.dk/wp-content/plugins/buddyboss-platform/bp-forums/functions.php on line 841But it seems like its something with groups. Text an line 841 (Strong) is this:
This loop works our way up to the top of the topic->sub-forum->parent-forum hierarchy..
// We will stop climbing when we find a forum_id that is also the id of a group’s forum..
// When we find that, we’ve found the group, and we can stop looking..
// Or if we get to the top of the hierarchy, we’ll bail out of the loop, never having found a forum.
// that is associated with a group..while ( ! $found_group_forum && ! $reached_the_top ) { $forum_group_ids = bbp_get_forum_group_ids( $forum_id ); if ( ! empty( $forum_group_ids ) ) { // We've found the forum_id that corresponds to the group's forum. $found_group_forum = true; $group_id = $forum_group_ids[0]; } else { $current_post = get_post( $forum_id ); <strong>if ( $current_post->post_parent ) {</strong> // $post->post_parent will be the ID of the parent, not an object. $forum_id = $current_post->post_parent; } else { // We've reached the top of the hierarchy. $reached_the_top = true; } } }
————————————–
Im not experienced enough with wp code to know where it would be smart to place the error_log().. If i could i would test if this is true:
if (array_key_exists('vis', $_GET ) && '92'== $_GET['vis']) {
and why term_id is not set to 24:
echo '<input type="hidden" name="term_id" value="24">';
Damn im tired of fighting with this..WP code is very complex to me and difficult to see through..
Did you test with exactly this code:
add_action( 'block_editor_meta_box_hidden_fields', 'add_cat', 10, 1 ); function add_cat($post) { if (array_key_exists('vis', $_GET ) && '92'== $_GET['vis']) { echo '<input type="hidden" name="term_id" value="24">'; } } add_action( 'save_post', 'save_cat' ); function save_cat( $post_id ) { if ( array_key_exists('term_id', $_POST )) { wp_set_post_terms($post_id,'24','category'); } }
Forum: Developing with WordPress
In reply to: Overwrite default post categoryI forgot that this is an open forum so i shouldnt write user and password here ??
I have changed it now. If you want to test this issue i can send user and password.Forum: Developing with WordPress
In reply to: Overwrite default post categoryHi again,
If i use the editor backend the screen looks like the one in your link.
So maybe its ok..
If you want to and have time to, you can try and login on my site : https://goaldigger.dk/
user: [redacted] , password: [redacted]– and then click on the running woman(L?b)
(in the middle below the large photo)– and then click on the text at the top “l?be 10 min”
– and then hover “Add new blog” and you can see the url with “?vis=92”
– when you click on this link you will come to the create new blog page.
You can try to add a new blog and see that the category still is “ikke kategoriseret” after submitting and refreshing the page.
Category should be “L?b”
Doesnt it look like same editor as Gutenberg editor backend ?Happy new year
- This reply was modified 4 years, 2 months ago by bcworkz.
Forum: Developing with WordPress
In reply to: Overwrite default post categoryNice that it works on your site. Thats a progress !
Maybe the problem is that i use the Buddyoress User Blog plugin:
https://www.buddyboss.com/product/buddypress-user-blog/I didnt know that it could be a problem.
Do you know if there is a hidden_fields action for this editor too ?Yes i meant that the term with ID=24 is being assigned to the current post.
Forum: Developing with WordPress
In reply to: Overwrite default post categoryI use quotes for [‘term_id’] now.
Im not used to work with the editor, and dont know where to find it. When i go to settings and writing there is no editor that i can choose.It seems, that i for some reason, dont change the value for term_id in the database.
add_action( 'block_editor_meta_box_hidden_fields', 'add_cat', 10, 1 ); function add_cat($post) { if (array_key_exists('vis', $_GET ) && '92'== $_GET['vis']) { echo '<input type="hidden" name="term_id" value="24">'; } } add_action( 'save_post', 'save_cat' ); function save_cat( $post_id ) { if ( array_key_exists('term_id', $_POST )) { wp_set_post_terms($post_id,'24','category'); } }
Forum: Developing with WordPress
In reply to: Overwrite default post categoryI really appreciate your detailed reply.
My code is like this now, but the category is still the default value.
Term_id is 1 and should be 24.
For some reason my code dont change the term_id.
Which database table shows the hidden field ? So i can check if something gets uploaded.add_action( 'block_editor_meta_box_hidden_fields', 'add_cat', 10, 1 ); function add_cat($post) { if (array_key_exists('vis', $_GET ) && '92'== $_GET['vis']) { echo '<input type="hidden" name="term_id" value="24">'; } } add_action( 'save_post', 'save_cat' ); function save_cat( $post_id ) { if ($_POST[term_id]) { wp_set_post_terms($post_id,'24','category'); } }
Yes it would maybe be more user friendly if the users is not able to choose a category. I will try to solve this problem afterwards.
Forum: Developing with WordPress
In reply to: Overwrite default post categoryI dont really know what im doing..
Its a long long shot ??
I guess i have to use the Gutenberg editor plugin ?
There are a lot of plugins, which one ? ??
Do i really need to use this plugin..Isnt possible just to insert a value, term_id, in the database. and delete it again ?add_action( 'block_editor_meta_box_hidden_fields', 'add_cat', 10, 1 ); function add_cat($post) { if ('92'== $_GET['vis']) { echo '<input type="hidden" name="term_id" value="24">'; } } add_action( 'save_post', 'save_cat' ); function save_cat() { if ($_POST[term_id]) wp_set_post_terms($post_id,'24','category'); }
Forum: Developing with WordPress
In reply to: Overwrite default post categoryI dont use the block editor. I really dont know what it is.
Most frustrating thing about this is that i know exactly what your idea is, and how to implement it if i coded my own PHP way.
I would then be a hidden field in a post form, and when submitted i could save it.
But here im too confused about which action, which variables and so i have to bring in.
But this is really an important functionality on my website so i have to go on working with this. Im not giving up on it!I will do this, and im kind of blind coding ?? but at least i will give it at try :
add_action( 'block_editor_meta_box_hidden_fields', 'add_cat', 10, 1 ); function add_cat($post) { if ('92'= $_GET[‘vis’]) { echo '<input type="hidden" name="term_id" value="loeb">'; } } function save_cat($_POST) { $_POST[term_id] = 'Loeb'; //if 92'= $_GET[‘vis’] i know that the category is "Loeb" } add_action( 'save_post', 'save_cat' );
Forum: Developing with WordPress
In reply to: Overwrite default post categoryI have also tried with this code but still without luck:
function save_suggestions_term( $post_id ) { if ( '92' == $_GET['vis']) { // name of your category. $suggestion_term = 'Loeb'; $taxonomy = 'category'; // The name of the taxonomy the term belongs in wp_set_post_terms( $post_id, array($suggestion_term), $taxonomy ); } } add_action( 'save_post', 'save_suggestions_term' );
Forum: Developing with WordPress
In reply to: Overwrite default post categoryThanks ??
Nice that you can help with this !Now i have this:
add_filter('wp_terms_checklist_args', 'my_cats_selected', 10, 2 ); function my_cats_selected( $args, $id ) { $post = get_post($id); // dont know if this is neccesary if ( '92' == $_GET['vis']) { $args['selected_cats'] = array( 24, ); } return $args;
But still, with or without line 3, after submitting i get the dafault category.
I think that $args will now return unchanged if $_GET[‘vis’] is not 92 with my code.Yes i know which category is assigned to the post when i know $_GET[‘vis’]
Hmmm its really difficult to see right now whats wrong with the code..Forum: Developing with WordPress
In reply to: Overwrite default post categoryYes now i can see its something from core code.
I use child themes function.php , so far so good.
My idea was actually that users shouldnt be able to change the category, but if its a big thing to code, i can live with this. Maybe i can write a comment at the page about not to change category.Now i have this, what do you think ?:
add_filter('wp_terms_checklist_args', 'my_cats_selected', 10, 2 ); function my_cats_selected( $args, $id ) { if (empty($_GET)) {return;} // with the "vis" post ID, get that post's cat term IDs else if $_GET['vis']== '92' { $taxonomy = 'category'; $selected_cats = '24'; $kat_id=24; //term_id } // if there are terms, assign to $args['selected_cats'] $args = array( 'selected_cats' => 24, 'taxonomy' => 'category' ); return $args; }
Forum: Developing with WordPress
In reply to: Overwrite default post categoryThank you very much, i really appreciate your help !
Im trying to follow your instructions and so far i have this:function wp_terms_checklist( $post_id = 0, $args = array() ) { If $_GET['vis']== 92 { $params = apply_filters( 'wp_terms_checklist_args', $args, $post_id ); $args['selected_cats'] = array('taxonomy' => $taxonomy); } }
I dont know how to assign the term_id, but i know that it should be:
term_taxanomy-id=24
term_id=24
taxanomy=categoryHow do i get these terms assigned to the post ?
And can you tell me if im on the track with my code ? ??- This reply was modified 4 years, 2 months ago by bcworkz. Reason: code fixed
Forum: Developing with WordPress
In reply to: Overwrite default post categoryThanks.
I don’t have much experience with wp and functions. I have though some experience with more simple php and MySql.
I have studied this case for several hours now and unfortunately i cant solve this problem.
If it was my own program it would not be a big problem, because i know how to get a variable from a URL and how to read and write to a database and so on, but when it comes to functions and the way that wp is build im a big question.
Can you help with the code or know someone i can pay to do this for me? ??
I have spent enough days just for this question now.