plugin development – URL issue retrieving Custom Post Types using Backbone JS API

I have a Custom Post Type called pronews. I registered it with show_in_rest enabled. I’m using WordPress 5.5.

I then have this code:

export const ProPost  = wp.api.models.Post.extend( {
    urlRoot: wpApiSettings.root + 'wp/v2/pronews',
    defaults: {
        type: 'pronews',
    },
} );
export const ProPosts = wp.api.collections.Posts.extend( {
    url: wpApiSettings.root + 'wp/v2/pronews',
    model: ProPost,
} );

const post = new ProPost( {id: 2454} );

console.log( post );
console.log( 'post urlRoot:' + post.urlRoot );
console.log( 'post url:' + post.url );

post.fetch().then( ( response ) => {
    console.log( response )
}, ( why ) => {
    console.log( why.responseJSON.code )
} );

// Double check that the endpoint is functionnal
fetch( wpApiSettings.root + 'wp/v2/pronews/2454' )
    .then( blob => blob.json() )
    .then( ( response ) => {
        console.log( response.id );
    } );

In the console I first get:

{…}
​_changing: false
​_pending: false
​_previousAttributes: Object { type: "pronews", id: 2454 }
​attributes: Object { type: "pronews", id: 2454 }
​changed: Object {  }
​cid: "c3"
​id: 2454
​<prototype>: Object { urlRoot: "https://localhost/wp-json/wp/v2/pronews", defaults: {…}, constructor: i()
 }
ProNews.js:17:9
post urlRoot:https://localhost/wp-json/wp/v2/pronews ProNews.js:18:9
post url:function(){var e=a.get("apiRoot")+a.get("versionString")+("me"===i?"users/me":i);return _.isUndefined(this.get("id"))||(e+="/"+this.get("id")),e} ProNews.js:19:9

But the Backbone API’s request is done to the wrong urlRoot :

XHRGET https://localhost/wp-json/wp/v2/posts/2454 (HTTP/1.1 404 Not Found 340ms)
rest_post_invalid_id

For debugging, the result of the second HTTP Request using window.fetch, shows that the endpoint for the Custom Post Type exists and is functional:

XHRGET https://localhost/wp-json/wp/v2/pronews/2454 (HTTP/1.1 200 OK 587ms)
2454

What Is Non Canonical Url?

 

javascript – Pasar datos de una página html a otra por medio de url

Necesito hacer un programa que envíe tres calificaciones y en la otra página imprima el promedio de los números, también si en mayor o igual a 50 o menor a 50, no importa el diseño, lo que importa es pasar los parámetros por medio de url sin uso de php, puro javascript y/o jqueary, ya por último que esa segunda página tenga el resultado pero sea visible en un div o form o lo que sea de la página 1, osea que al ingresar los datos y apachurrar el boton, envíe todos los datos a la página 2 pero que no redireccione a esa página, sino que cargue la página 2 en la 1, no sé si me explico XD

8 – Updating a Node image field from an external URL

I need to retrieve an image from an external URL and then save the image on Drupal’s file system, and then set the image as the image for a node. In D7, this was a pretty simple task, but it’s causing me issues in D8. In D7, here is what we have:

$file_info = system_retrieve_file($url, 'public://course_images/', TRUE);
if(!empty($file_info) && $file_info->fid) {
    $entity->field_image(0) = array('fid' => $file_info->fid);
}

I am trying the same thing in D8 but just receive this error Value is not valid entity which provides ZERO actual information about exactly what is wrong.

In D8, here is what I currently have:

$file = system_retrieve_file($image_url, 'public://course_images/', TRUE, FileSystemInterface::EXISTS_REPLACE);

if ($file && $file->id) {
  $course_node->set('field_image', (
    'target_id' => $file->id,
    'alt' => 'alt text',
    'title' => 'title'
  ));
}

I’ve also tried using $file->id() and $file->fid with no luck. I just don’t know how to access the file entity id!

I have tried to debug the $file object to figure this out using the logger

Drupal::logger('my_module')->notice('<pre><code>' . print_r($file, TRUE) . '</code></pre>');

but this code is in a cron job and adding that logger just makes the cron job fail with no error other than ‘Cron cannot get lock’ (again, another error with little to no information).

I can see that my file is being saved properly, but how can I access it’s node ID after saving to be able to set as the target_id of the image field?

I will promote 10 High Quality Quora Answer with Keyword and URL for $4

I will promote 10 High Quality Quora Answer with Keyword and URL

WELL COME TO MY GIG

Quora is one of the best and active question answer site ​that can provide both traffic and very high quality backlinks to your website.Quara answer’s give you very high quality PA , DA backlinks. I will give you 100% Guarantee for your site boost on google rank and increase organic traffic . Now a days quora is one of the most well know social media and platfrom to get my question answer and niche related website traffic.Great for SEO and get more organic traffic from Each link will go on an answer.

My Service Specialities :

  • All answer are Informative & natural.
  • No copy paste.
  • Use of correct language.
  • 100% unique and particular specialty associatedanswer content.
  • Guaranteed Traffic And Backlinks.
  • High-Quality answer Content
  • Ranking on google
  • All answer submit only

I have prepared myself to work on your project and giving you the best service ever Feel free to ask questions at any time.

.

Custom post type category, taxonomy and URL rewrite problem

I’m fairly new to wordpress and I’m working on a website which has an abundant category of products.
I want to create a custom post type to add a bunch of products. I’m going to demonstrate what I am trying to achieve and then elaborate on the problems I have faced.

Here is my requirements:

  1. I need to categorize my products by brand and functionality and it needs to be translated to:

by brand:

example.com/products/sub-category/product-name
eg. domain.com/products/toshiba/toshiba-E-Studio-2518A

by functionality:

example.com/products/functionality-category/product-name
eg. domain.com/products/color-printer/toshiba-E-Studio-2518A

As you can see in the example above, the product is categorized under more than one category.

  1. I need each of these categories and taxonomies to have an archive page (or any page that contains all of the relevant posts)

eg. domain.com/products/toshiba/ -> show all toshiba products

eg. domain.com/products/color-printer/ -> show all color printers

eg. domain.com/products/ -> show all products

What I have tried so far:

  • First I tried creating it using CPT ui, I used categories in my custom posts and it solved 50% of the problem. but then the URL slug of the category cannot be as same as the custom post slug.
  • I created a plugin so I could have more control, still no luck.Followed this article and many more to be honest

I’m having a tough time with this issue for almost a week now and really cannot find a solution to it, so I would appreciate some help.

thanks