Add meta field in corepost-template wordpress - Stack Overflow

i'm trying to find a way to add some custom field in the post template that lies under the corequ

i'm trying to find a way to add some custom field in the post template that lies under the core/query of wordpress. The idea is to add in this post-template a div with a data-id element containing the value of my custom field (that is already added in every custom post in the back end) Right now, i'm able to catch the meta query of my posts inside a custom block that inherits the query loop. It works in the edit.js part, in the editor, my loop append the meta field (i integrate it in a data-id label) correctly for each post. But i'm not able to do it on the save.js for the front end as it only register one meta field value. Maybe i'm missing something in the way the query loop works. If somebody has some idea or clue in order for me to move on. Thank you!

Here's my block.json

"$schema": ".json",
    "apiVersion": 3,
    "name": "my-block/test",
    "version": "0.1.0",
    "title": "Test",
    "ancestor": [ "core/query" ],
    "parent": ["core/post-template"],
    "usesContext": [
        "queryId",
        "query",
        "displayLayout",
        "templateSlug",
        "previewPostType",
        "enhancedPagination",
        "postType",
        "postId"
    ],

my edit.js

export default function Edit({ attributes, setAttributes, context }) {
    const { cardId, postId } = attributes;

    const meta = useEntityProp('postType', context.postType, 'meta', context.postId);
    meta ? setAttributes({ cardId: meta[0].my_cpt }) : "";
    
    setAttributes({ postId: context.postId })
    const blockProps = useBlockProps({
        "data-id": cardId,
        "className": postId
    });

    return (
        <div  {...blockProps}>
            <InnerBlocks />
        </div>
    );
}

my save.js

export default function Save({ attributes }) {
    const { cardId, postId } = attributes;
    const blockProps = useBlockProps.save({
        "data-id": cardId
    });

    return (
        <div { ...blockProps }>
            <InnerBlocks.Content />
        </div> 
    );
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744841568a4596585.html

相关推荐

  • Add meta field in corepost-template wordpress - Stack Overflow

    i'm trying to find a way to add some custom field in the post template that lies under the corequ

    2天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信