Form을 이용하여 Post 편집하기

  • comment10 comments

워드프레스에서 프로폼을 사용하여 프론트엔드에서 글을 수정하는 방법을 설명합니다.

사전준비

2개의 페이지가 기본적으로 필요하고 편집버튼이 있는 포스트 리스트와 편집화면 페이지가 필요합니다. 중요한 것은 포스트 리스트의 편집버튼을 눌렀을 때 필요한 데이터들이 편집화면페이지로 전달되어져야 합니다.

편집버튼(Edit button) 설정

  • Link type : External URL
  • URL : /edit-post/?id={포스트_id} ** 여기서 /edit-post/는 편집화면 페이지의 slug입니다.

편집화면 페이지 만들기

섹션 > 컨테이너 > Pro Forms 구조를 만든 후 Submit을 제외한 Pro Forms의 기본 필드들을 삭제합니다.

  • Post title : Text field
  • Post Content : Richtext field
  • Featured Image : File field
  • Taxonomy (Category) : Checkbox wrapper 필드 > Checkbox필도 구조로 만듭니다.
  • Hidden : Submit을 실행하였을 때 데이터를 해당 Post에 Overwrite 할 수 있도록 Post 정보를 설정합니다.

각 Pro Forms 필드에 동적데이터 할당하기

Post title

  • Custom ID : 식별하기 쉬운 아이디를 할당합니다. ex) post_title, post_content, post_excerpt, etc…
  • Label : Title
  • Value : {brf_post_title:{유아렐_parameter:id}}

Post content

  • Custom ID : post_content
  • Label : Content
  • Value : {brf_post_content:{유아렐_parameter:id}}
  • Width : 100%
  • Style : Flat Toolbar

Featured image

  • Custom ID : featured_image
  • Label : Featured Image
  • Value : {brf_post_thumbnail_url:{유아렐_parameter:id}}
  • Width : 100%
  • Action : Choose files
  • max. files : 1
  • Replace file : Enable
  • Max. size (MB) : 1
  • Allowed file types : jpeg,jpg,webp
  • Hide Image Preview : Disable
  • Disable file deletion : Enable
  • Preview image width : 200
  • Preview image object fit : Cover

Checkbox Wrapper

  • Custom ID : post_taxonomy
  • Label : Post Category

Checkbox (Query loop)

Query Loop

  • Type : Terms
  • Taxonomies : Categories (Post)
  • Show empty : Enable

Checkbox

  • Label : {텀_name}
  • Value : {텀_slug}
  • Conditionally Checked : Enable
  • Checked if : Is Enable Post Taxonomy Term
  • Post ID : {유아렐_parameter:id}
  • Taxonomy Key : category ** Custom Taxonomy를 사용할 경우 Custom Taxonomy의 이름을 입력합니다.

Hidden

  • Custom ID : my_post_id
  • Value : {유아렐_parameter:id}

생성한 폼에게 Action 부여하기

편집화면 페이지의 폼에 입력한 후 Submit 했을 때 어떠한 Action을 수행할 지 설정합니다.

  • Actions after successful form submit : Update post
  • Success message : (예시)글이 성공적으로 업데이트 되었습니다.

Update Post 설정

위 Action을 Update post로 설정하게 되면 Update Post 설정메뉴가 활성화 됩니다. 각각의 필드에 위에서 설정한 Pro Forms의 Custom ID를 {{Custom ID value}}로 감싸며 입력합니다.

  • Post ID : {{my_post_id}}
  • Post Title : {{포스트_title}}
  • Post Content : {{포스트_content}}
  • Post Status : draft, pending, publish, future, private 등 중에서 선택
  • Post Excerpt :
  • Post Date :
  • Post Thumbnail : {{피쳐드_image}}
  • Post Taxonomies : Add (+) 아이콘을 선택한 후
    • Taxonomy Slug : category (or Custom Taxonomy’s name)
    • Term : {{포스트_category}}

Pro Forms 의 Form Reset 기능 비활성화 하기

편집할 때 기존 입력했던 데이터 값들이 Reset 되는 것을 비활성화 하기 위해서는 Pro Froms 요소의 설정옵션 중 “OTHER” 옵션에서 Disable Form Reset 을 활성화합니다.

인기글

16

2월

불켜진 전구를 들고 있는 손이미지

워드프레스에서 프로폼을 사용하여 프론트엔드에서 글을 수정하는 방법을 설명합니다.

Leave the first comment