How to choose the last member of an array in a datalayer? - google-tag-manager

Then I would like to get the smallest child Category of a post that belongs lots of categories (via the datalayer pageCategory used plugin called GTM4WP by Duracell Tomi).
How can I do that?
I had already known to get the biggest category: pageCategory.1
Already tried pageCategory.10 or pageCategory.length-1 but didn't work. I'm not really familiar with Javascript. Please guide me

You need to use the length of the array, but with a different syntax:
pageCategory[pageCategory.length-1]

Related

Querying Two Wordpress Categories via URL

I have posts that are assigned to two categories let's say cars and paints. I'm trying to only get posts that are in both, the following code http://example.com/category/cars+paints is supposed to work according to this article but it doesn't and I get a page saying The requested document was not found on this server. When I try http://exapmle.com/category/cars,paints it works but it gives me too many posts.
It seems that & is supposed to work as well, I tried http://exapmle.com/category/cars&paints and http://exapmle.com/category/?cat=cars&cat=paints but this doesn't either work, I don't know if I have the syntax wrong.
When I try http://exapmle.com/?cat=1&cat=2 using the category IDs it directs to a page like this http://exapmle.com/category/paints with the last parameter corresponding to the last number entered in the URL.
Does anyone know why it's not working and what I can do to get it to work, thanks in advance.
Changing the + to a space %20 seems to be working for me
Example:
http://example.com/category/cars%20paints

User access to CPT (Custom Post Type) without access to regular posts

I have created a custom post type that for the sake of this question we can call "my_cpt".
I have also created a new role which we can call "my_role".
What I want to do is give "my_role" access to "my_cpt" without adding the "edit_posts" capability because that gives access to other post types which I do not want the role to have access to.
I have tried variations of numerous bits of code I have found but none have worked so I don't really know where to begin. Based on that I don't have any base code to display here.
A plugin like this one should enable you to do this: https://www.role-editor.com/
Ended up being easier than I thought.
I created a couple capabilities... "read_my_cpt" and "edit_my_cpt".
The "my_role" has permissions to both the capabilities.
I then just had to change the capability_type for the CPT to "my_cpt" instead of "post"

Use two taxonomy terms in one URL WP-API

At the moment I'm calling taxonomy term data using URL's like this -
http://scd.blaze.wpengine.com/wp-json/posts?type=listings&filter[listing_area]=northwest
Is there a way I can call two taxonomy terms at the same time, something like this? -
http://scd.blaze.wpengine.com/wp-json/posts?type=listings&filter[listing_area]=northwest&filter[listing_area]=northeast
I've read through all documentation but I'm struggling to find a solution, andy help would be much appreciated, thanks in advance!
Without knowing the full code in place its hard to be 100% but try...
http://scd.blaze.wpengine.com/wp-json/posts?type=listings&filter[listing_area][]=northwest&filter[listing_area][]=northeast
By adding [ ] to the end of each reference to listing_area you are now passing through an array of values. Otherwise you just pass through the last value in the query string.

How to add fictional category wordpress

I'm trying to do something, on wordpress which i'm not sure is possible.
So basically, I'm using Magic fields for two things. I've created a panel called "Member", and another one called "Member actuality". I've created two categories, member and member actuality which I've binded too magic fields post.
When I go on category (site.com/category/member) member I have the list of all my members.
When I click on one of my members (site.com/memberName) I have the description of the member. So for the moment everything is ok.
Now what I want to do is find a way too display actuality of one member. Maybe something like : (site.com/actuality/member) But I have no clue on how to do that. So if someone can help me.
I'm not sure i've explained it right, so please if you didn't understand ask me to reformulate.
Thanks for your future help
I found a way to do go throu this.
I've first created a new tag when a post was added, and that allowed me to use the tag directory which i didn't used before !
!

How to find which menu a node belongs to in drupal

I currently have nodes setup on my site, and each node belongs to a particular menu (not primary or secondary prebuilt menues).
How can i find out which menu a node belongs to?
Maybe this is what you mean:
$trail = menu_get_active_trail();
$lastInTrail = end($trail);
$menu_name = $lastInTrail['menu_name'];
menu_get_active_trail() returns a breadcrumbs like array, the last breadcrumb represents the current node.
Cheers,
Laurens Meurs, Rotterdam
I'm a noob, so don't bash me if what I'm going to write is worthless babbling.
I think you can't do that directly, unless there's some smart module out there that would do all the nasty SQL queries necessary to check this.
Node info is stored in the SQL table "node", and is identified merely by NID (node ID, which is the node number that appears after /?q=node/ in the address). Their aliases, if any, are stored in "url_alias" table, where you can find columns "src" and "dst", identifying the original and the aliased path (for instance, src='node/123', dst='my/url/alias'). The menu links can be found in the table "menu_links", where you can find the columns "menu_name" (the machine-radable name of a menu) and "link_path" (either the node/... or the alias).
So, what you'd need to do is the following:
get the current node's NID
query "url_alias" if there's an alias for node/NID and retrieve it, otherwise leave node/NID
query the "menu_links" table for the path you've determined and retrieve "none" or the menu's machine-readable name
You could then also query the table "menu_custom" to check what's the human-readable name of the menu you've determined.
Anyway, that's a complicated query (several queries?) and I'm a MySQL ignorant, so I can't help you with the actual code you'll need to use to check all that :P.
This isn't a direct solution and I see from your reply to a previous answer that you didn't wanted the simplest solution possible, but I thought I'd mention this option. The Menu Node API module maintains a table which Drupal lacks, a node-menu relationship table.
The module does nothing on its own, but there seems to be contributed modules which build on this, so depending on how complex your problem is it might be a starting point.
http://drupal.org/node/584984
Updated: Sorry guys, didn't even realize I had posted this link. I think I intended it as a draft and simply posted it when closing tabs. That said, mingos (above) is right on.
My link is to a function menu_get_active_menu_name() that appears to provide you with an array containing the active menu for the current page. As I presume that is what you are using it for, it would be a nice way to abstract yourself away from the database calls that might cause problems down the line.
I myself have never tried it, which is probably why I didn't elaborate and post. well... at least didn't post on purpose.

Resources