0.1.21 • Published 9 years ago

dispobiz-node-wordpress v0.1.21

Weekly downloads
67
License
-
Repository
github
Last release
9 years ago

dispofi-node-wordpress

Fonctions de récupération des posts Wordpress (PHP) réinterprétées pour nodejs

Installation

npm install dispobiz-node-wordpress

Utilisation

var dnw = require('dispobiz-node-wordpress');

var numSite = 1;
var sqlConnexion = {
	host: 'localhost',
	port: '3306',
	user: 'user',
	password: 'pass',
	database: 'db'
};

dnw.create(numSite, sqlConnexion);

Récupération d'un post en fonction de son id

var idPost = 15;
dnw.loadPost(idPost).then(function (post) {
	console.log(post.post_name, post.post_title);
}, function (error) {
	console.log(error)
});

Récupération d'un post en fonction d'une url (post_name)

var url = 'le-plan-de-numerotation-telephonique';
dnw.loadPostFromUrl(url).then(function (post) {
	console.log(post.post_title);
}, function (error) {
	console.log(error)
});

Données liées au post (auteur, tags, categories, ariane)

dnw.loadPostData(47, 'category').then(function (postdata) {
  // postdata sous la forme : { auteur: '', tags: [], categories: [], ariane: {} }

  // Arrays
  postdata.tags.forEach(function (tag) {
    console.log('tag', tag.name);
  });
  postdata.categories.forEach(function (category) {
    console.log('category', category.name);
  });

  // Objects
	console.log('auteur', postdata.author.display_name);
	console.log('ariane', postdata.ariane.category.name + ' > ' + postdata.ariane.subcategory.name);

}, function (error) {
	console.log(error);
});

Récupération d'une catégorie en fonction du slug

dnw.loadCategory('non-classe').then(function (category) {
	console.log(category.term_id, category.slug);
}, function (error) {
	console.log(error)
});

Données liées à la catégo

dnw.loadCategoryData('actualites', 'category').then(function (postdata) {
  // postdata sous la forme : { category: {}, ariane: {} }

  // Objects
  console.log('category', postdata.category.name);
  console.log('ariane', postdata.ariane.category.name + ' > ' + postdata.ariane.subcategory.name);

}, function (error) {
  console.log(error);
});

Récupération des posts liés à une catégorie (id (Integer) ou slug (String) en paramètre)

var idCategory = 1;
dnw.loadPostsFromCategory(idCategory, 'category').then(function (posts) {
	posts.forEach(function (post) {
		console.log(post.ID, post.post_name);
	});
}, function (error) {
	console.log(error)
});

Récupération des catégories

dnw.loadAllCategories().then(function (categories) {
	categories.forEach(function (category) {
		console.log(category.slug, category.name);
	});
}, function (error) {
	console.log(error)
});

Recherche d'un ou plusieurs posts

// Paramètres facultatifs
var categoryId = 1;
var conditionBase = [{ key: 'post_type', value: 'post' }];
var conditionSupp = [{ champs: '_edit_last', signe: '=', valeur: 1}];
var order = { champs: 'post_title', type: 'desc' };
var limit = 2;

dnw.searchPosts(categoryId, conditionBase, conditionSupp, order, limit).then(function (posts) {
	posts.forEach(function (post) {
		console.log(post.post_title);
	});
}, function (error) {
	console.log(error)
});

Récupération d'un auteur (et des métas first_name, last_name et description)

dnw.loadUser('admin').then(function (user) {
  console.log(user.display_name); // wp_users
  console.log(user.description);  // wp_usermeta (champs meta_key)
});

Auteur du post

dnw.loadUserFromPost(4).then(function (name) {
	console.log(name);
}, function (error) {
	console.log(error)
});

Liste des tags d'un post

dnw.loadCategoTagsPost(15, 'post_tag').then(function (tags) {
	tags.forEach(function (tag) {
		console.log(tag.slug, tag.description)
	});
}, function (error) {
	console.log(error)
});

dnw.loadCategoTagsPost(15, 'category').then(function (categories) {
	categories.forEach(function (category) {
		console.log(category.name, category.slug)
	});
}, function (error) {
	console.log(error)
});

Métas d'un auteur

dnw.loadUserMeta(1).then(function (usermeta) {
	console.log(usermeta.wp_user_level, usermeta.source_domain);
}, function (error) {
	console.log(error)
});

Valeur d'une option en fonction du nom

var optionName = 'widget_categories';
dnw.getOptionValue(optionName).then(function (value) {
	console.log(value);
}, function (error) {
	console.log(error);
});
0.1.21

9 years ago

0.1.20

9 years ago

0.1.19

9 years ago

0.1.18

9 years ago

0.1.17

9 years ago

0.1.16

9 years ago

0.1.15

9 years ago

0.1.14

9 years ago

0.1.13

9 years ago

0.1.12

9 years ago

0.1.11

9 years ago

0.1.10

9 years ago

0.1.9

9 years ago

0.1.8

9 years ago

0.1.7

9 years ago

0.1.6

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago