-
Hello there,
While using your latest code to update focus keywords automatically I have found that the below query is taking too long to process data.
Custom code which you have provided in the previous support ticket No: #224818
function update_focus_keywords() {
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'post' // Replace post with the name of your post type
));
foreach($posts as $p){
// Checks if Rank Math keyword already exists and only updates if it doesn't have it
$rank_math_keyword = get_post_meta( $p->ID, 'rank_math_focus_keyword', true );
if ( ! $rank_math_keyword ){
update_post_meta($p->ID,'rank_math_focus_keyword',strtolower(get_the_title($p->ID)));
}
}
}
add_action( 'init', 'update_focus_keywords' );
Data from Query Monitor :
Caller:
update_meta_cache()Query:
SELECT post_id, meta_key, meta_value
FROM QtAEVu6axs_postmeta
WHERE post_id IN (2436,2433,2442,2427,2417,2453,2430,2439,2424,2408,2399,2411,2387,2384,2375,2365,2450,2393,2390,2356,2359,2371,2378,2342,2349,2402,2330,2343,2320,2353,2297,2293,2290,2325,2396,2287,2284,2405,2281,2445,2269,2266,2259,2246,2240,2231,2249,2224,2243,2456,2227,2184,2217,2192,2188,2157,2170,2181,2163,2207,2237,2154,2146,2142,2137,2130,2125,2121,2113,2094,2097,2100,2087,2103,2084,2081,2106,2252,2090,2076,2073,2031,2059,2038,2012,2010,1989,2004,1979,1995,1976,1998,1973,1986,1992,2020,2017,1983,1925,1922,1915,1899,1878,1867,1855,1843,1849,1837,1832,1813,1804,1807,1852,1781,1761,1752,1758,1767,1770,1792,1734,1743,1778,1725,1822,1722,1864,1746,1764,1716,1718,1737,1784,1713,1728,1795,1701,1704,1681,1692,1659,1688,1675,1695,1819,1740,1872,1627,1623,1614,1609,1631,1606,1592,1602,1589,1598,1586,1569,1572,1563,1544,1541,1513,1538,1498,1489,1486,1474,1453,1444,1428,1422,1480,1410,1559,1413,1375,1441,1425,1366,1528,1363,1360,1501,1465,1354,1345,1384,1516,1333,1369,1307,1313,1298,1324,1272,1275,1232,1224,1215,1209,1221,1200,1269,1172,1187,1166,1250,1318,1144,1163,1141,1128,1131,1138,1160,1184,1124,1203,1253,1227,1260,1097,1100,1091,1081,1118,1088,1212,1059,1074,1106,1050,1068,1032,1035,1009,1000,1003,1062,1024,985,1071,953,959,1437,1157,947,938,973,994,917,1047,911,988,1121,944,956,991,1015,1181,896,1038,929,1197,902,890,1053,1387,887,932,1244,1103,935,893,920,1263,1292,1316,1397,1416,878,1439,1462,1477,1495,1525,1532,1556,869,905,1456,970,1026,1289,866,1327,860,1471,881,1519,850,847,1553,856,1078,843,835,1006,832,817,829,820,799,802,826,796,811,808,784,778,790,787,853,1295,805,772,757,769,766,875,745,760,926,982,730,727,718,742,697,685,688,691,676,634,631,661,637,625,610,664,640,607,703,733,619,751,658,655,694,598,568,589,562,580,577,565,736,559,604,592,583,548,543,518,721,520,515,524,512,503,495,500,530,491,478,534,469,460,447,443,463,453,450,430,432,652,715,421,372,409,338,359,366,404,341,392,332,427,335,345,352,355,509,326,383,775,1256,323,415,1400,1338,667,739,380,320,313,475,418,309,540,1021,1112,1154,1194,1241,306,303,1286,297,899,300,292,289,967,574,286,1381,616,283,646,682,280,272,1041,265,276,269,262,259,256,252,246,240,249,234,191,1175,172,169,162,157,154,151,147,1235,1301,237,243,709,1447,137,1504,1826,88,85,82,79,77,362,527,472,412,348,628,586,673,700,748,781,814,863,908,941,976,1012,1044,1085,1115,1147,1178,1218,1247,1278,1310,1357,1390,1431,1459,1492,1522,1547,1575,1635,1710,1755,1801,1846,1911,2007,2042,2117,2263,2368,2420,369,435,488,551,595,622,670,724,754,793,838,884,914,950,997,1029,1056,1094,1135,1169,1206,1229,1266,1304,1342,1372,1419,1450,1483,1507,1535,1566,1618,1707,1749,1798,1840,1908,2001,2032,2109,2256,2362,2414,376,457,537,601,649,712,763,823,872,923,979,1018,1065,1109,1151,1191,1238,1283,1321,1378,1434,1468,1510,1550,1595,1698,1731,1775,1829,1905,387,424,466,506,546,571,613,643,679,706)
ORDER BY meta_id ASCThis makes my website very slow. please provide any solution if possible(I have also attached the screenshot of the slow query, Please have a look at it too).
Regards,
Sachin
The ticket ‘Query took too long to process after adding your custom code to funtions.php’ is closed to new replies.