Duplicated content "Group by og distinct" Virker ikke på min kode
HejHvordan man får fjernet duplicated content.
For selv om jeg har bruget Group by og distinct vil det stadig ikke virke.
Har kæmpet med det men kan bare ikke få det til at virke.
En stor lang smøre håber i kan overskue det, eller sig endelig til.
Er ikke så god til at få lavet beskrivelser til min kode.
Noget jeg skal have øvet min på
Min kode:
global $wpdb;
$xml = new XMLWriter();
// Used to write to xml file - uncomment the next line to print xml to a file
$xml->openURI('****_nyhedsbrev.xml');
// used for string output from memory
// $xml->openMemory(); // comment this line to print xml to a file
//set the indentation to true
$xml->setIndent(true);
//create the document tag
$xml->startDocument('1.0', 'utf-8');
$xml->startElement("items"); // start Items
// faste værdier
$antal_pr_side = 200; // denne værdi skal ændres
$offset = 0;
$data = array();
$data1 = array();
$run = true;
while ($run) {
$con = $wpdb->__get('dbh');
$stmt = $con->prepare("SELECT **_posts.ID, **_posts.post_date, **_posts.guid, **_posts.post_modified, **_posts.post_parent, **_posts.post_title, **_posts.post_type, **_postmeta.post_id, **_postmeta.meta_value, **_postmeta.meta_key
FROM **_posts INNER JOIN **_postmeta ON **_posts.ID = **_postmeta.post_id WHERE **_posts.post_type in ('product', 'attachment' ) and **_postmeta.meta_key in ('_wp_attached_file', '_stock', '_sku', '_regular_price', '_sale_price', '_thumbnail_id') LIMIT " . $offset . "," . $antal_pr_side." ");
$stmt->execute();
$rs = $stmt->get_result();
$lng = $rs->num_rows;
$stmt1 = $con->prepare("SELECT **_posts.ID, **_posts.post_type, **_postmeta.post_id, **_postmeta.meta_value, **_postmeta.meta_key
FROM **_posts INNER JOIN **_postmeta ON **_posts.ID = **_postmeta.post_id WHERE **_posts.post_type in ('attachment' ) and **_postmeta.meta_key in ('_wp_attached_file') LIMIT " . $offset . "," . $antal_pr_side." ");
$stmt1->execute();
$rs1 = $stmt1->get_result();
while ($row = $rs->fetch_array(MYSQLI_ASSOC)) {
$data[] = $row;
while ($row1 = $rs1->fetch_array(MYSQLI_ASSOC)) {
$data1[] = $row1;
if ($row1['meta_key'] == "_wp_attached_file") {
global $meta_image_url;
$meta_image_url = $row1['meta_value'];
}
}
global $meta_regular_price;
global $meta_sale_price;
global $meta_sku;
global $post_title;
global $post_type;
global $meta_image_url;
global $meta_stock;
global $brand;
global $post_parent;
global $guid;
global $koen;
if ($row['meta_key'] == "_sku") {
global $meta_sku;
$meta_sku = $row['meta_value'];
}
$brand_name = get_the_terms($row['ID'], 'product_brand');
foreach ($brand_name as $item) {
global $brand;
$brand = $item->name;
}
$koen = get_the_terms($row['ID'], 'product_cat');
foreach ($koen as $item) {
global $koenet;
$koenet = $item->parent;
}
global $koen;
$koen = $koenet;
$terms = get_the_terms($row['ID'], 'product_cat');
foreach ($terms as $term) {
if ($term->parent == 0) {
global $koen;
$koen = $term->name;
}
}
$post_title = $row['post_title'];
$guid = get_permalink($row['ID']);
if ($row['meta_key'] == "brand") {
global $product_brand;
$product_brand = $row['value'];
}
$post_modified = $row['post_modified'];
$post_parent = $row['post_id'];
if ($row['meta_key'] == "_regular_price") {
global $meta_regular_price;
$meta_regular_price = $row['meta_value'];
}
if ($row['meta_key'] == "_sale_price") {
global $meta_sale_price;
$meta_sale_price = $row['meta_value'];
}
if ($row['meta_key'] == "_stock") {
global $meta_stock;
$meta_stock = $row['meta_value'];
}
$xml->startElement("item"); // start Item
$xml->writeAttribute('ExternalId', $meta_sku);
$xml->writeAttribute('Modified', $post_modified);
$xml->writeAttribute('Name', $post_title);
$xml->writeAttribute('ImageLink', $meta_image_url);
$xml->writeAttribute('AdditionalImageLink', $meta_image_url);
$xml->writeAttribute('Link', $guid);
$xml->writeAttribute('Gender', $koen);
$xml->writeAttribute('Brand', $brand);
$xml->writeAttribute('InStock', $meta_stock);
$xml->writeAttribute('ItemGroupId', $post_parent);
$xml->writeAttribute('RegularPrice', $meta_regular_price);
$xml->writeAttribute('SalePrice', $meta_sale_price);
$xml->endElement(); //End Item
}
if ($lng < $antal_pr_side) {
$run = false;
}
if ($lng == 0) {
break;
}
$offset += $antal_pr_side;
}
$xml->endElement();
// Display thue current buffer
$xml->flush();