[WordPress] 워드프레스 이전 후 카테고리와 댓글 수 이상 문제 해결 방법

워드프레스를 이전하고 나서, 카테고리가 제대로 나타나지 않는다거나, 카테고리 내의 글 갯수가 이상하게 표시되는 경우, 댓글이 이상한 경우 등이 있다.

https://www.wpbeginner.com/wp-tutorials/how-to-fix-category-and-comment-count-after-wordpress-import/ 의 방법을 따르면 된다.

요약하면 UpdraftPlus를 이용해서 사이트 백업 후, 다음 파일을 wordpress 디렉토리 내부에 comments-fix.php로 저장한 후 이를 브라우저에서 로딩해서 실행한다. 내부의 DB_HOST, DB_USER, DB_PASSWORD, DB_NAME 등을 바꾼다. 나의 경우, “localhost”, “dasomoli”, “PASSWORD”, “wordpress” 로 바꿔주었다.

<?php
include("wp-config.php");
$myConnection = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD)) {  die('Could not connect: ' . mysqli_error());  }
if (!mysqli_select_db($myConnection, DB_NAME)) {  die('Could not connect: ' . mysqli_error());  }
  
$result = mysqli_query($myConnection, "SELECT term_taxonomy_id FROM ".$table_prefix."term_taxonomy");
while ($row = mysqli_fetch_array($result)) {
  $term_taxonomy_id = $row['term_taxonomy_id'];
  echo "term_taxonomy_id: ".$term_taxonomy_id." count = ";
  $countresult = mysqli_query($myConnection, "SELECT count(*) FROM ".$table_prefix."term_relationships WHERE term_taxonomy_id = '$term_taxonomy_id'");
  $countarray = mysqli_fetch_array($countresult);
  $count = $countarray[0];
  echo $count."<br />";
 mysqli_query($myConnection, "UPDATE ".$table_prefix."term_taxonomy SET count = '$count' WHERE term_taxonomy_id = '$term_taxonomy_id'");
        }
  
$result = mysqli_query($myConnection, "SELECT ID FROM ".$table_prefix."posts");
while ($row = mysqli_fetch_array($result)) {
  $post_id = $row['ID'];
  echo "post_id: ".$post_id." count = ";
  $countresult = mysqli_query($myConnection, "SELECT count(*) FROM ".$table_prefix."comments WHERE comment_post_ID = '$post_id' AND comment_approved = 1");
  $countarray = mysqli_fetch_array($countresult);
  $count = $countarray[0];
  echo $count."<br />";
  mysqli_query($myConnection, "UPDATE ".$table_prefix."posts SET comment_count = '$count' WHERE ID = '$post_id'");
        }
?>

[Notion] 편집 시 마크다운 문법과 단축키

마크다운 문법

  • *, - , +space: Bullet 목록 블록으로 변경
  • 1space: 번호 목록 블록으로 변경
  • #space: 제목 1 블록으로 변경, ##은 제목 2, ###은 제목 3
  • >space: 토글 목록 블록으로 변경
  • ---: 구분선
  • "space: 인용 블록으로 변경
  • []: 할 일 목록 블록으로 변경
  • **텍스트**: 굵게
  • *텍스트*: 이탤릭체
  • `텍스트`: 코드
  • ~텍스트~: 취소선

단축키

  • Ctrl + Shift + 0 또는 Cmd + Option + 0: 텍스트 블록으로 변경
  • Ctrl + Shift + 1 또는 Cmd + Option + 1: 제목 1 블록으로 변경
  • Ctrl + Shift + 2 또는 Cmd + Option + 2: 제목 2 블록으로 변경
  • Ctrl + Shift + 3 또는 Cmd + Option + 3: 제목 3 블록으로 변경
  • Ctrl + Shift + 8 또는 Cmd + Option + 8: 코드 블록으로 변경