Excluding Custom Taxonomy Terms from a CPT Archive Page - wordpress-theming

After referring to all the other posts about similar subjects, and attempting to Frankenstein together a solution, I've decided to do the thing I never do and ask for help. :)
I need to have specific posts tagged with specific terms from a custom taxonomy excluded on a Custom Post Type Archive page only (so they still show up in their own individual archive pages)
The CPT: 'Guest' - default slug is 'guest' -but the archive slug is set to 'guests' (I've tried using both)
The Taxonomy: Guest Type - slug is also set to 'guests'*
**Code I've come up with so far: **
// Guest Archive Category Exclusions --->
function exclude_posts( $query ) {
if ( $query->is_archive('guest') ) {
$query->set( 'guests', array( -180, -205, -179 ) ); //Exclude inMemorium, Postponed, Alumni
}
}
add_action( 'pre_get_posts', 'exclude_posts' );
//END Guest Archives Category Exclusions <--
Thank You so much for your help!
*totally off-topic explanation for the curious - the slugs were both set to 'guests' on purpose since there is no archive page set for a taxonomy type. Bonus points if you know how to activate one.
I've tried multiple things from the other threads on similar topics.
They either break the site or do nothing.

Related

Connecting one dropdown list to another perl

In Perl, I have script that creates a dropdown list based on a database that contains a list of vendors. I would like to use the selection of the first list to populate the second list with values of different contacts given that specific vendor.
ie. Haliburton is vendor....once this is chosen contact Jim, Paul, George are available in contact list that is next to it.
Currently I am getting the list of vendors and the list of contacts separately. How do I get the list of contacts based on the vendor in the database to be populated in the CGI popup_menu?
The following is my current code:
#!c:\perl\bin\perl.exe
use CGI;
use strict;
use warnings;
require ("data_eXchangeSubs.pm");
$query = new CGI;
print $query->header(-expires=>'-1d');
print $query->start_html(-title=>'Dex Vendor Testing',
-bgcolor=>'white'
);
my $dataX = ${ConnectToDatabase($main::DB1, $main::DBEnv)};
$resultSet = $dataX->Execute("select vendor from vendor_info group by vendor");
my #list_of_vendors;
while(!$resultSet->EOF) {
push #list_of_vendors, $resultSet->Fields("vendor")->Value;
$resultSet->MoveNext;
}
From here, I would like to populate another dropdown list with contacts from the vendor_info data table. Currently I'm making a separate query execution but I would like to take a given vendor from the previous array and populate only those contacts specific to the chosen vendor.
I know I have to change the values of the contacts but don't know how to :(
$resultContact = $dataX->Execute("select contact from vendor_info");
my #list_of_contacts;
while(!$resultContact->EOF) {
push #list_of_contacts, $resultContact->Fields("contact")->Value;
$resultContact->MoveNext;
}
print $query->popup_menu(
-name => 'vendors'
, -values =>\#list_of_vendors
, -default => $default_vendor
, -style=> 'width:200px'
);
print $query->popup_menu(
-name => 'contacts'
, -values => \#list_of_contacts
, -default => $default_vendor
);
print $query->end_html;
This is a very broad question. You have a couple of simple options.
1) Create an HTML form with the list of vendors, take (and sanitize!) the user's selection, and return the list of contacts. This is a traditional dynamic CGI form.
2) Use JavaScript. This only works for a reasonable amount of data. There are several ways to do it but the gist of the idea is: a) associate each contact with the correct vendor, b) hide all the contacts initially, c) when a vendor is selected, display the correct contacts.
JQuery is a handy JavaScript tool for this kind of manipulation and magically hides many browser incompatibility problems.
3) You could create a fancy, modern AJAX-ified form, but from your question, this is probably overkill.
Sorry there is no quick-and-dirty solution but I'm hoping to give you enough here to start Googling in the right direction! Best!
With CGI, you need to use CGI::param method.
# I know the name of the select is "vendors",
# but it makes more sense calling it here with 'vendor'
# *you would have to change the name of the element*
my $vendor_name = $query->param( 'vendor' );
And I'm not sure how your database object works (kind of looks like the Microsoft iteration model), but using the proper way of parameterized queries in DBI, it looks like this:
my $stmt = $dbh->prepare( 'select contact from vendor_info where vendor_name=?' );
$stmt->execute( $vendor_name ); # binds the variable to the query.
Then you step through the rows of the query and build your list of contacts. Of course, you'd mostly likely use fetchrow_array or fetchrow_arrayref methods to walk through them.
Although this might be better off utilizing a more modern strategy by getting a combined list of vendors and contacts for JavaScript or using Ajax to query the contacts for a vendor.
There is no "connecting" structure in basic Perl CGI. You would have to use a more modern web framework for that.

magento table "sales_flat_order" field "protect_code" explanation

We are working on magento database and tables. Magento seems to write a code in table sales_flat_order field protect_code to define if there is a invoice or a shipment done already. It would look something like
01b335 or
a0a243
But there is no key to understand what this protection code means. Is there an explanation of the meaning of these codes and how they are generated?
Where is it generated?
If you look in app/code/core/Mage/Sales/Model/Order.php on around line 2052, you will find the following:
$this->setData('protect_code', substr(md5(uniqid(mt_rand(), true) . ':' . microtime(true)), 5, 6));
This is where protect_code is generated for the order (using a combination of md5, uniqid, and random integer.
What is it used for?
If you look in app/code/core/Mage/Sales/Helper/Guest.php and find the loadValidOrder function. You will see protect_code used in some areas to ensure the order being loaded is the correct one for the guest's cookie value.
It's also used in other areas, such as tracking information comparisons. You can see several instances of the getProtectCode() method being called in the Shipment models to compare the order to the tracking information. An example of a function that uses it is:
public function getTrackingInfoByTrackId()
{
$track = Mage::getModel('sales/order_shipment_track')->load($this->getTrackId());
if ($track->getId() && $this->getProtectCode() == $track->getProtectCode()) {
$this->_trackingInfo = array(array($track->getNumberDetail()));
}
return $this->_trackingInfo;
}
As you can see with $this->getProtectCode() == $track->getProtectCode(), the tracking protect_code must match the Shipment protect_code.

CakePHP Displaying Field Names via Two Associations

I apologize for the confusing title, I was a little stumped as to how to word my question.
I am new to CakePHP, but am following along through the cookbook/tutorials nicely, however I have come up against something which I cannot find an answer to.
My structure is as follows:
'Invoices' hasMany 'InvoiceHistory'
'InvoiceHistory' belongsTo 'InvoiceHistoryDeliveryStatus'
Whereby, an invoice can have multiple invoice histories, and each history contains a delivery status id, which links to a name.
On the Invoice view (index.ctp) I am displaying a list of all invoices but wish to display the Most Recent Delivery Status Name (InvoiceHistory contains a date field so it can be sorted) - thereby displaying the 'current Delivery Status'.
When I do:
$this->set('invoices', $this->Invoice->find('all'));
It does not go deep enough in what it returns to provide me with Delivery Status Names, nor have I deduced a way of only returning the most recent Invoice History within my result. I know how to do this manually with a MYSQL query but I figured that is probably just plain wrong.
What is the correct way of going about this while following CakePHP conventions?
Use Containable
$this->Invoice->Behaviors->attach('Containable');
$this->set('invoices', $this->Invoice->find('all', array(
'contain' => array(
'InvoiceHistory' => array(
'InvoiceHistoryDeliveryStatus'
)
)
));
From what I can tell, I think you should check out the Containable behavior.

WordPress 'Custom Post Type' gets set to wrong Taxonomy Term IDs

First and foremost, I need to stress how greatly I appreciate anyone who takes the time to respond - In advance, thank you, thank you, THANK YOU!
I feel pictures are of great service to explaining things, so to start off, here's something of an illustration of the issue:
http://i.stack.imgur.com/b9OXR.png
Preface:
My site has about 400 Posts under the "dir_listing" Custom Post Type
Each "dir_listing" Post can be associated with Terms from the "listing category" Custom Taxonomy and/or "listing_region" Custom Taxonomy
I have about 210 "listing_category" Terms, and 155 "listing region" Terms
The Issue in Summary:
When Publishing or Updating a "dir_listing" Post Type, sometimes the Term IDs get recorded into the 'term_relationships' table without issue, and other times are recorded erroneously.
Even so, when I go back to edit one of the "dir_listing" Post Types the checkboxes for the desired Parent/Child Terms are correctly marked.
Actions that could be Related?
A number of the "listing_category" terms have been shuffled around. (e.g. A Parent term has become a Child term, or vice-versa, or a Child term has been moved to another Parent.)
Both Parent & Child Terms have been renamed without making any changes to the "dir_listing" Post types. (I don't think this matters, since Posts are supposed to be related to Terms by ID #)
A number of Parent Terms and Child Terms may have been deleted by another Admin-level user. This also seems to happen with Child-Terms of the "listing_regions" taxonomy.
How I've Investigated / Tried to Fix It:
Extensively searched WordPress trac (No similar issues reported)
Searched Google for things like *"wordpress tax_input bug"*, "wordpress taxonomy id bug", "wordpress custom taxonomy bug", etc. and found no matching issues
Disabled all plugins, custom rewrites, and other taxonomies
Ensured the checkbox inputs had the correct Taxonomy as their 'name' and Term ID as their 'value'
Hacked the /wp-admin/includes/post.php core file to try to fix it myself. (No luck.)
Posted issue to [WordPress "How-To and Troubleshooting" forum][3] this morning (No replies)
Posted issue to Reddit /r/web_design this afternoon (Also no replies)
I've spent the better part of 8 hours trying to determine the cause of this, or if I'm missing a step by using a custom MySQL query to directly get a list of Posts related to a particular Term ID.
Again, any thoughts or suggestions anyone might have are VERY MUCH appreciated - Thanks!
This info might help you with how the term_id and and term_taxonomy_id work. It seems like there are a lot of conditions that effect the final outcome of how the ids are set.
See the full reference here: http://phpxref.com/xref/wordpress/wp-includes/taxonomy.php.html#wp_insert_term
Also have a look at this trac ticket regarding the need for a posts relationship table and some of the use cases.
get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw') X-Ref
Get all Term data from database by Term ID.
The usage of the get_term function is to apply filters to a term object. It
is possible to get a term object from the database before applying the
filters.
$term ID must be part of $taxonomy, to get from the database. Failure, might
be able to be captured by the hooks. Failure would be the same value as $wpdb
returns for the get_row method.
There are two hooks, one is specifically for each term, named 'get_term', and
the second is for the taxonomy name, 'term_$taxonomy'. Both hooks gets the
term object, and the taxonomy name as parameters. Both hooks are expected to
return a Term object.
'get_term' hook - Takes two parameters the term Object and the taxonomy name.
Must return term object. Used in get_term() as a catch-all filter for every
$term.
'get_$taxonomy' hook - Takes two parameters the term Object and the taxonomy
name. Must return term object. $taxonomy will be the taxonomy name, so for
example, if 'category', it would be 'get_category' as the filter name. Useful
for custom taxonomies or plugging into default taxonomies.
param: int|object $term If integer, will get from database. If object will apply filters and return $term.
param: string $taxonomy Taxonomy name that $term is part of.
param: string $output Constant OBJECT, ARRAY_A, or ARRAY_N
param: string $filter Optional, default is raw or no WordPress defined filter will applied.
return: mixed|null|WP_Error Term Row from database. Will return null if $term is empty. If taxonomy does not
get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw') X-Ref
Get all Term data from database by Term field and data.
Warning: $value is not escaped for 'name' $field. You must do it yourself, if
required.
The default $field is 'id', therefore it is possible to also use null for
field, but not recommended that you do so.
If $value does not exist, the return value will be false. If $taxonomy exists
and $field and $value combinations exist, the Term will be returned.
param: string $field Either 'slug', 'name', or 'id'
param: string|int $value Search for this term value
param: string $taxonomy Taxonomy Name
param: string $output Constant OBJECT, ARRAY_A, or ARRAY_N
param: string $filter Optional, default is raw or no WordPress defined filter will applied.
return: mixed Term Row from database. Will return false if $taxonomy does not exist or $term was not found.
get_term_children( $term_id, $taxonomy ) X-Ref
Merge all term children into a single array of their IDs.
This recursive function will merge all of the children of $term into the same
array of term IDs. Only useful for taxonomies which are hierarchical.
Will return an empty array if $term does not exist in $taxonomy.
param: string $term ID of Term to get children
param: string $taxonomy Taxonomy Name
return: array|WP_Error List of Term Objects. WP_Error returned if $taxonomy does not exist

How do I create my own custom group in mediawiki?

I have been reading carefully through the MediaWiki documentation but I have not been able to find out how to create new groups.
When I look at Special:Userrights, I see only 3 groups :
Bots, Sysops, Bureaucrats
I would like to create my own custom groups, so I can use some extensions like the http://www.mediawiki.org/wiki/Extension:Group_Based_Access_Control.
Can someone tell me how it's done, or point me to some documentation?
You can add permissions for new groups to your LocalSettings.php file and they will automatically appear in the Special:UserRights page.
For example, I wanted to disallow editing by regular users but create a "Trusted" group that was allowed to edit. The following code creates a "Trusted" group that is equal to the "user" group, except that "Trusted" users can edit but "user" users cannot.
$wgGroupPermissions['Trusted'] = $wgGroupPermissions['user'];
$wgGroupPermissions['user' ]['edit'] = false;
$wgGroupPermissions['Trusted']['edit'] = true;
$wgGroupPermissions['sysop' ]['edit'] = true;
On the Special:UserRights page, I can now check the "Trusted" box to make users trusted.
You can alter the appearance of the group name by creating the following messages:
(For a group named ninja:)
MediaWiki:Group-ninja (content: Ninjas)
MediaWiki:Group-ninja-member (content: ninja)
MediaWiki:Grouppage-ninja (content: Project:Ninjas)
This will insure that the group will be referred to as "Ninjas" throughout the interface, and a member will be referred to as a "ninja", and overviews will link the groupname to Project:Ninjas.
(source: http://www.mediawiki.org/wiki/Manual:User_rights#Examples)
Here you will find a List of Permissions. http://www.mediawiki.org/wiki/Manual:User_rights
I beleive I have found the answer, I just need to add the UserGroup and the permission to the wgGroupPermissions array in the LocalSettings.php file.
$wgGroupPermissions['TomatoUsers']['read'] = true;
$wgGroupPermissions['TomatoUsers']['edit'] = false;
I don't have the reputation to vote up the first answer (which can also be added to extension initialization files), but for when you get to adding users to your groups you may want to consider directly editing the database (ie. if you need to sync the wiki groups with external information). If you open the database "wikidb" the "PREFIX_user_groups"* table contains the mapping between user IDs (ug_user) and group names (ug_group). This table, combined with the "PREFIX_user"* table's name information (user_name) and ID information (user_id), give you all the information to add and remove large numbers of users from groups.
* Replace "PREFIX" with the database prefix you used for your wiki.