• Resolved pank6119

    (@pank6119)


    I m a newbie using OceanWp Theme on my WordPress Website I just Want To Add a field of yoost focus keyword in quick edit of all post . I have created many post without any focus keyword and its not getting difficult to add focus keyword to all field here is my code below which is not working pls help me modifying and debugging this code i m new to this so need some help

    add_action( ‘quick_edit_custom_box’, ‘my_quick_edit_custom_box’, 10, 2 );function my_quick_edit_custom_box( $column_name, $post_type ) { if ( ‘yoast_focus_keyword’ === $column_name ) { ?> <fieldset class=”inline-edit-col-right inline-edit-yoast-focus-keyword”> <div class=”inline-edit-col”> <label> <span class=”title”><?php esc_html_e( ‘Yoast Focus Keyword’, ‘textdomain’ ); ?></span> <span class=”input-text-wrap”> <?php $keyphrase = get_post_meta( get_the_ID(), ‘_yoast_wpseo_focuskw’, true ); ?> <input type=”text” name=”yoast_focus_keyword” value=”<?php echo esc_attr( $keyphrase ); ?>”> </span> </label> </div> </fieldset> <?php }}

    Thanks In Advance Pls help Me to just get/add a field of focus keyword in under quick edit tab of all post

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator t-p

    (@t-p)

    I recommend asking at https://www.ads-software.com/support/plugin/wordpress-seo/#new-post so its developers and support community can help you with this.

    Moderator bcworkz

    (@bcworkz)

    To add fields to the quick edit form, use the “quick_edit_custom_box” action.

    That just lets you output a form field. You need code to save any altered values. The “save_post” action can work for that.

    Thread Starter pank6119

    (@pank6119)

    @bcworkz Thank U for help But I m a newbie It would be Really difficult for me to learn nd understand so much In coding All I have done From plugins ,helps and by help of chatgpt.

    I Found The Plugin “Custom Bulk/Quick Edit” Which I is quite close to the function I want . It gives additional option like Excerpt field added to quick edit I thought of buying its premium too but I think That plugin owner and team are now not in Touch with that plugin itself. they didn’t even Respond To wordpress blog. So Only thing possible for me is either to go round way or to learn All Things On my own I Thought Sharing Code Here can give me Easy Expert advice about what’s wrong In that code.

    add_action( 'quick_edit_custom_box', 'my_quick_edit_custom_box', 999, 2 );
    function my_quick_edit_custom_box( $column_name, $post_type ) {
        if ( 'yoast_focus_keyword' === $column_name ) {
            ?>
            <fieldset class="inline-edit-col-right inline-edit-yoast-focus-keyword">
                <div class="inline-edit-col">
                    <label>
                        <span class="title"><?php esc_html_e( 'Yoast Focus Keyword', 'textdomain' ); ?></span>
                        <span class="input-text-wrap">
                            <?php $keyphrase = get_post_meta( get_the_ID(), '_yoast_wpseo_focuskw', true ); ?>
                            <input type="text" name="yoast_focus_keyword" value="<?php echo esc_attr( $keyphrase ); ?>">
                        </span>
                    </label>
                </div>
            </fieldset>
            <?php
        }
    }
    
    add_action( 'save_post', 'my_save_post_custom_field' );
    function my_save_post_custom_field( $post_id ) {
        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
            return;
        }
    
        if ( isset( $_POST['yoast_focus_keyword'] ) ) {
            $keyphrase = sanitize_text_field( $_POST['yoast_focus_keyword'] );
            update_post_meta( $post_id, '_yoast_wpseo_focuskw', $keyphrase );
        }
    }

    Above Code is created by chatgpt so I can’t understand , Why it’s not working for me I need help on this

    Moderator bcworkz

    (@bcworkz)

    I’m sorry, I didn’t investigate this filter thoroughly enough. The ChatGPT code might be fine, I’ve not looked in detail because the filter doesn’t fire at all under default situations. To get it to fire, you need to add your own custom column to the posts list table. Once that is done, then this filter gives you the opportunity to place a field related to the column so users can quick edit that value as well.

    Custom columns aren’t that well documented, although there is in fact a page doing so somewhere in WP support docs. However my search-fu is failing me, can’t find it. The original source article the support doc was based upon is linked above.

    I realize this is all getting pretty complex for your level of coding skill, but it is what it is. Maybe ChatGPT will come through for you again if you prompt it well ?? Good luck!

    Thread Starter pank6119

    (@pank6119)

    Well Frankly To Say I Still Didnt Understood What I Really Have to do But I know Code of Chatgpt is correct But incomplete and Rest I found this Link of that plugin I told You earlier Which I tried To explore https://developer.www.ads-software.com/reference/hooks/manage_post_type_posts_columns/

    Again Not being so Good In It I m still confused about what to do adding anoter code to wp-admin/includes/class-wp-posts-list-table.php to post table list or adding another function in function.php with given code of chatgpt . I know chatgpt Will evolve and correct if asked properly So which way should I go Extremely sorry For causing this trouble for u. all i know is I just want to retrieve and update a column from database which is ‘_yoast_wpseo_focuskw’. i don’t even want bulk edit just quick edit for this column bcoz it takes too much time to edit 1000’s of post without focus keyphrase to add one by clicking on edit and adding them while viewing the full post.

    Thank u in Advance I will try to find a way or if u could help more on my way then it will be less time consuming for me.

    Moderator bcworkz

    (@bcworkz)

    what to do adding anoter code to wp-admin/includes/class-wp-posts-list-table.php

    I’m not sure what you actually imagined doing by “adding anoter code”. To be clear, we must never add code to existing WP core files. It’s good practice to never modify any code in WP that’s not our own. All changes to default WP behavior should be done via action and filter hooks. Your own code can reside in its own plugin or child theme.

    Unless you can find a plugin to help you add quick edit fields, I don’t see any easier way. Adding to quick edit is even less well documented than adding custom list table columns, whose docs are sparse enough.

    An alternative approach to update a DB column would be to use wpdb class methods to directly update the fields you want to change via mySQL queries. The new values would be included in the update code itself, there’d be no UI to speak of for altering records one at a time.

    Thread Starter pank6119

    (@pank6119)

    It was very difficult for me to create new or modify the plugin with no or less knowledge And Time To create custom field for yoost focus keyword so i came up with an Idea After going through Working of Plugin “custom Bulk/Quick edit ” And documentation that it add custom column to quick edit form when u add new column in database using

    add_filter( ‘manage_post_posts_columns’, ‘my_manage_post_posts_columns’ );function my_manage_post_posts_columns( $columns ) {$columns[‘custom_stuff_here’] = esc_html__( ‘custom Stuff here’ ); return $columns;}

    so i added a new custom field then ran a small code asking chat gpt to replicate all data of Focuskw column to new column then deleted that code after one time run then added a new code again asking chatgpt to update Yoost Wpseo Focuskw in database with data of new custom column whenever custom column is updated and now i can quick edit yoost Wpseo Focuskw indirectly through quick edit form new custom colum

    Moderator bcworkz

    (@bcworkz)

    I’m glad you found a solution you can use! A clever approach which best fits what you know.

    Thread Starter pank6119

    (@pank6119)

    Thank u For all Your generosity and Help @bcworkz Resolved ???

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Pls Help Me To Add Yoost focus keyword (keyphrase) field in quick edit of WordPr’ is closed to new replies.