D
D
Danil Ostapenko2021-09-15 06:30:22
WordPress
Danil Ostapenko, 2021-09-15 06:30:22

How to get custom fields from a revision?

Good day, I can’t make friends getting custom fields from revisions of custom post types (yes, they are registered and they have revisions), I tried different options, and through wp_get_post_revisions and through get_children , displaying a list of revisions for a post was no problem, but getting an arbitrary the field from the revision is the whole problem.

Code options:

Via wp_get_post_revisions
<?
        $get_meta_revs = wp_get_post_revisions( $id_obj );

        foreach ( $get_meta_revs as $get_meta_rev ) { ?>

            <? echo $get_meta_rev->ID; ?>
            <? echo get_field( 'phone1', $get_meta_rev->ID );?>
            
        <?}?>

Через get_children:
<?
            $get_meta_revs = get_children( array(
                'post_parent'    => $id_obj,
                'post_type'      => 'revision'
            ) );
            foreach ( $get_meta_revs as $get_meta_rev ) { ?>

                <? echo $get_meta_rev->ID; ?>
                <? echo get_field( 'phone1', $get_meta_rev->ID );?>

            <? } ?>



I also tried to get custom fields through get_field , get_post_meta In desperation, I

even tried to collect IDs in an array in a loop and output them through a standard WP_Query query

In all options, revisions and all info on them are displayed, but not custom fields :|

I will immediately answer the questions:
- Creation of revisions for an arbitrary type of records is indicated and they are created - checked.
(screenshot from admin)
6141698ff3b6b220534621.png

- Yes, the post ID of which I am looking for revisions is - checked.
- Yes, I get revision data with all the info (and revision ID, etc.)
- Through the standard revision check (console > desired entry > revisions), I see changes to this custom field.
- Custom post type created through the plugin: Post Type Builder
- Custom post type registered
- Custom fields created through the plugin: Advanced Custom Fields PRO

- Screen just in case that the revisions themselves are pulled out, but custom fields cannot be pulled up.
Screen

614167f353269615274591.png

PS In the query surf, it either throws on chips with revisions or on buns of arbitrary fields, but together I did not find an option.

Thanks in advance !

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Zolin, 2021-09-16
@artzolin

Read this https://wordpress.stackexchange.com/questions/2219...
And this is https://github.com/adamsilverstein/wp-post-meta-re...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question