You are here:  » Custom post type


Custom post type

Submitted by babrees on Wed, 2017-09-06 10:09 in

Hi David

Could I get the plugin to insert into a custom post type, rather than the default 'post'?

Cheers
Jill

Submitted by support on Wed, 2017-09-06 10:53

Hi Jill,

Sure - "post" is referred to literally a couple of times in pto_common.php - first look for the following code around line 62:

    $retval = get_permalink(get_page_by_title($product->name,"OBJECT","post"));

...and REPLACE with:

    $retval = get_permalink(get_page_by_title($product->name,"OBJECT","custom_post_type"));

And then the following code at line 274:

  if ($p = get_page_by_title($product->name,"OBJECT","post"))

...and REPLACE with:

  if ($p = get_page_by_title($product->name,"OBJECT","custom_post_type"))

And then look for the following code at line 281:

  $post["post_title"] = $post["post_name"];

...and REPLACE with:

  $post["post_title"] = $post["post_name"];
  $post["post_type"] = "custom_post_type";

In all cases above, replace custom_post_type in the replacement code with your custom post type as required...

Cheers,
David.
--
PriceTapestry.com

Submitted by babrees on Wed, 2017-09-06 11:56

Thanks David!

Now you know what a pest I am!

What about custom category?

Submitted by support on Wed, 2017-09-06 14:00

Hi Jill,

The actual post category field is set to the feed category (if not empty) by the following code at beginning at line 287 of pto_common.php:

  if ($pto_productResults[0]->category)
  {
    $post["post_category"] = array(wp_create_category($pto_productResults[0]->category));
  }

If you just wanted to set your own, fixed category value for each post then you could REPLACE the above with:

  $post["post_category"] = "Custom Category";

On the other hand, if you wanted to set a custom field e.g. "CUSTOM_CATEGORY" to the feed category value, then this can be done by adding another field to the array used as the value for the meta_input field from the modification described here for example:

   $post["meta_input"] = array(
      "CUSTOM_IMAGE_URL"=>$pto_productResults[0]->image_url,
      "CUSTOM_CATEGORY"=>$pto_productResults[0]->category
      );

Cheers,
David.
--
PriceTapestry.com

Submitted by babrees on Wed, 2017-09-06 14:14

Thanks David.

I'm useless at explaining what I want!

I will have a custom category (taxonomy) type, and want it to behave exactly as it does but to add/use the custom taxonomy instead. In other words, sub-categories created

I hope that's clear LOL!

With your latter example, would that still create sub-categories for my custom-category?

Submitted by support on Thu, 2017-09-07 07:44

Hi Jill,

Just to clarify, you want posts of have a 2-tier taxonomy of

Your Custom Category > Feed Category

Thanks!
David.
--
PriceTapestry.com

Submitted by babrees on Thu, 2017-09-07 11:33

Hi David

So glad you worded it!!!

No. I will just have a custom taxonomy (category-pt), so not 2 tier.

Cheers
Jill

Submitted by support on Thu, 2017-09-07 12:09

Hi Jill,

No problem! So to set a custom taxonomy of "category-pt" instead of the post category to the feed category value, look for the following code beginning at line 287 of pto_common.php:

  if ($pto_productResults[0]->category)
  {
    $post["post_category"] = array(wp_create_category($pto_productResults[0]->category));
  }

...and REPLACE with:

  if ($pto_productResults[0]->category)
  {
    $post["tax_input"] = array("category-pt" => $pto_productResults[0]->category);
  }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by babrees on Mon, 2017-09-11 06:54

Thanks David!

Will give it a whirl! :)

Submitted by babrees on Thu, 2017-10-26 14:15

Hi David.

I know this is sometime since you gave me a reply on this, but I'm only just getting around to the site again!!!

I tried your first reply in order to import them to a custom post type, but I can't get it to work. All it does is just import them to the default post type still!

Submitted by support on Fri, 2017-10-27 08:49

Hello Jill,

Assuming the custom post type you are using is registered that should be all that is required - would you be able to to a test with just a few products but using "page" instead of "post"?

If still not working as expected, if you could email me the modified pto_common.php I'll check it out further with you ...

Cheers,
David.
--
PriceTapestry.com

Submitted by uck on Tue, 2017-12-19 13:33

Hi David,

I actually got the same problem as the previous customer while trying to import as custom type.

I have also tried to import as page, but what I get are post.

Any suggestion?

Regards

Submitted by support on Tue, 2017-12-19 15:08

Hi,

My apologies there was a mistake in the final modification to pto_common.php described in the first reply in this thread - the new code beginning at line 281:

  $post["post_title"] = $post["post_name"];
  $post["post_type"] = $post["custom_post_type"];

...should be:

  $post["post_title"] = $post["post_name"];
  $post["post_type"] = "custom_post_type";

(or "page" instead of "custom_post_type" to test as pages)

Corrected above.

Cheers,
David.
--
PriceTapestry.com

Submitted by uck on Tue, 2017-12-19 20:30

It works! Thank you!