How get period index status google api? - google-search-console

debug($sitemaps->listSitemaps("http://example.com",
['contents'=> 'indexed']));
return
object(Google_Service_Webmasters_SitemapsListResponse) {
[protected] collection_key => 'sitemap'
[protected] internal_gapi_mappings => array()
[protected] sitemapType => 'Google_Service_Webmasters_WmxSitemap'
[protected] sitemapDataType => 'array'
[protected] modelData => array(
'sitemap' => array(
(int) 0 => array(
'path' => 'http://example.com/sitemap.xml',
'lastSubmitted' => '2017-12-31T17:06:56.592Z',
'isPending' => false,
'isSitemapsIndex' => false,
'type' => 'sitemap',
'lastDownloaded' => '2018-01-03T11:42:39.262Z',
'warnings' => '0',
'errors' => '0',
'contents' => array(
(int) 0 => array(
'type' => 'web',
'submitted' => '4',
'indexed' => '0'
)
)
)
)
)
[protected] processed => array()
}
modeldata should return an array of data with dates and indexing values

I fear it's not part of the Search Console API as of yet. There's this post on the Google Product Forum as well: https://productforums.google.com/forum/?hl=en#!topic/webmasters/KIUsaXpquKY;context-place=topicsearchin/webmasters/category$3Awebmaster-tools%7Csort:relevance%7Cspell:false
I haven't seen any changes since then, so I wouldn't hold my breath if I were you.
The closest you can get to some number from the API, indicating the amount of pages indexed by Google, is by summing all the contents[].indexed of all the sitemaps and/or sitemap indexes that you have submitted. Probably you only submitted one sitemap index that references all sitemaps, so if you request that one using Sitemaps:get (https://developers.google.com/webmaster-tools/search-console-api-original/v3/sitemaps/get) you get the total of pages indexed.
But that number is poorly correlated to the actual Index status, that you can find in the Search Console UI, in ways that I don't properly understand.
I would think that if you have a sitemap.xml that contains every page of your website, the sum of contents[].indexed would be closely math the total number of pages indexed. That doesn't seem to be the case.

Related

Get_term with meta_query

I can figure out this query : my purpose is to have a list of taxonomys (category like) with the number posts related to. Something like :
Concerts (4)
Theater (10)
Cinema (12)
...
"Events" posts are store in a CPT 'event' and they all have an "event_start_date" ACF field. If I don't use the meta_query the "get_term" output well all the post by taxonomy. As soon as I try to get all posts from today's date (with the meta_query), nothing appear.
$terms = get_terms( array(
'post_type' => 'events',
'hide_empty' => false,
'taxonomy' => 'events_category',
// 'orderby' => 'name',
// 'order' => 'ASC',
// 'meta_query' => $meta_query_array_from_today,
'meta_query' => array(
array(
'key' => 'event_start_date',
'value' => date( "Ymd"),
'type' => 'date',
'compare' => 'LIKE',
),
)
) );
I've read a lot of answers but i can't make it works, some of answers found do a ne WP-Query but I don't want post, I need a list of taxonomy (using term->count).
If anyone can guide me, I would be grateful.
Thank's !

Creating an Advanced Search field capable of searching multiple module fields

I am currently encountering issues trying to build a custom search field (itself bound to an unused field on a Module) to search two Phone Number fields. The documentation covering modifications of a search field are really poor, but I have the following in place in the module's SearchFields.php
'phone' =>
array (
'query_type' => 'default',
'operator' => '=',
'db_field' =>
array (
0 => 'home_phone_c',
1 => 'work_phone_c',
),
),
The field itself returns no results, so am I missing something that would prevent this from working?
why not you use "sub-query" operator for this? See SearchFields.php inside metadata folder of Account module. You will see entry like following:
'email' =>
array (
'query_type' => 'default',
'operator' => 'subquery',
'subquery' => 'SELECT eabr.bean_id FROM email_addr_bean_rel eabr JOIN email_addresses ea ON (ea.id = eabr.email_address_id) WHERE eabr.deleted=0 AND ea.email_address LIKE',
'db_field' =>
array (
0 => 'id',
),
'vname' => 'LBL_ANY_EMAIL',
),
this will help you to understand the sugar logic of doing it.
You need to designate the correct tables. Try the below code (or use the tables that you're searching):
'phone' =>
array (
'query_type' => 'default',
'operator' => '=',
'db_field' =>
array (
0 => 'accounts_cstm.home_phone_c',
1 => 'accounts_cstm.work_phone_c',
),
),

zf2 doctrine form int required not working

$inputFilter->add(array(
'name' => 'seatingCapacity',
'required' => TRUE,
'filters' => array(
array('name' => 'Int'),
),
));
In my Doctrine Entity, I have a getInputFilter method which I use for form validation. The above is code snippet for one of the input elements. My problem is the required => true is not working even if I submit an empty form.
After researching I found out, that the Int filter converts the empty input to 0 and submits it and that is why the required validator is not working. I just need reasons why it may not be working.
For reference where I searched
Zend Framework 2 - Integer Form Validation
where he suggests to use Between validator
$inputFilter->add($factory->createInput(array(
'name' => 'zip',
'required' => true,
'filters' => array(
array('name' => 'Int'),
),
'validators' => array(
array(
'name' => 'Between',
'options' => array(
'min' => 1,
'max' => 1000,
)
)
)
)
));
I want to know why I should use Between and why required is failing.
You should only use the Between validator to validate if the given value is Between a min and max value. It has nothing to do with solving your empty value to 0 issue.
You should ask yourself 2 questions:
Is 0 a valid value?
Do I want to automatically cast null empty string ('') and other empty values to this 0 or not?
If you actually want to prevent that the Int filter sets an empty value to 0, maybe then you should not use this filter at all then?
You can instead add an IsInt validator to check if the given value is an integer. Your required => true setting will work as expected and validation will fail on any other (not integer) input so also on null, empty strings etc.
Thank you for your time, energy & effort.
Actually I solved the problem.
I had copy-pasted the code, which I should have been careful while doing so.
What I found out is there is no such filter named 'Int' and actually it's 'Digits'
$inputFilter->add(array(
'name' => 'seatingCapacity',
'required' => TRUE,
'filters' => array(
array('name' => 'Int'),
),
));
shows me error because the filter name should have been 'Digits'.
Only doing so solved my problem and works as per my requirement.
$inputFilter->add(array(
'name' => 'seatingCapacity',
'required' => TRUE,
'filters' => array(
array('name' => 'Digits'),
),
));
This is the right way to do and I would advice you to be careful while referring code from your sources because it's an illogical mistake I did.
Happy coding

wordpress WP Query and Custom Field filtering

I've encoutered problem with filtering pages to display in WP query.
I use Codex WP query reference for custom fields with ACF (Advanced Custom Fields plugin - but it doesn't matter, couse it works same as WP custom field) parameters to filter pages.
In "Multiple Custom Field Handling" paragraph, Codex got an example with 2 conditions. We can use OR or AND relation. I works for both until you have 3rd condition (array).
They use example:
'relation' => 'OR',
array(
'key' => 'color',
'value' => 'blue',
'compare' => 'NOT LIKE'
),
array(
'key' => 'price',
'value' => array( 20, 100 ),
'type' => 'numeric',
'compare' => 'BETWEEN'
)
It has only 2 arrays. When I put 3rd, nothing shows. In debug mode I can see an error:
WordPress database error: [Lost connection to MySQL server during query]
When I use AND it works, but I got to use OR. Unfortunately it makes MySQL disconnect.
I've tryed asking phpMySQL for same query WP does. It couses problem - phpMyAdmin says same:
Lost connection
Any Idea?
Maybe I should try different aproach for filtering? (maybe I should use taxonomy?)
Here is code I use:
$query_array = array('relation' => 'OR');
array_push($query_array,
array(
'key' => 'filter1',
'value' => 'value1',
'compare' => 'LIKE'
),
array(
'key' => 'filter1',
'value' => 'value2',
'compare' => 'LIKE'
),
array(
'key' => 'filter1',
'value' => 'value3',
'compare' => 'LIKE'
)
);
$args = array(
'order' => $order_array,
'meta_key' => $meta_key,
'orderby' => $orderby,
'post_type' => 'page',
'paged' => $paged,
'post__in' => $postIDs,
'posts_per_page' => 12,
'paged' => get_query_var('paged'),
'meta_query' => $query_array
);
query_posts($args);
?>
(variables for $args are set of course)
I don't know why I can't use
'compare' => '='
but probably it is why I can't use:
$query_array = array('relation' => 'OR');
array_push($query_array,
array(
'key' => 'filter1',
'value' => array('value1', 'value2', 'value3'),
'compare' => 'IN'
)
);
Just wanted to say that your comment helped me; I'd been butting my head against a very similar problem for a while. I'm using ACF too, and using it to attach items of one post type to another custom post type was easy - for instance, to Attach Person_1 and Person_3 to "Project_A".
This made it easy to list out which users were attached to specific projects. But when it came to do the same in reverse - to show which projects were attached to which users - it became a massive headache.
I finally figured it out, in part thanks to your comment - I'll post my solution here in case someone else comes along with the same problem:
$args = array(
'numberposts' => -1,
'post_type' => 'project',
'meta_query' => array(
'relation' => 'IN',
array(
'key' => 'people',
'value' => ';s:1:"' . $person->ID . '";',
'compare' => 'LIKE'
)
)
);
In short: because the ACF values in repeater fields et cetera are serialized, the compare keyword has to be "LIKE", and I added some context to the value to eliminate false returns - just searching for an ID like "1" would match a lot of the (wrong) posts, but the ";s1;" part ensures that the given value is at index 1, which in my case is the correct index.
So it would need tweaking from case to case. Inspecting what you're trying to match up with var_dumping "get_post_meta($post->ID, 'people')" is helpful for getting the value correct.

Grabbing Facebook life events

Ive been looking for a way to pull recent life events for friends from the graph API but I've ran into a blocker for locations.
I know you can query friends for their location. But is it possible to find previous location history (or just history in general, if someone was given a promotion at work so they change their role?).
Excuse the lack of code as I'm posting from my mobile.
What I have for locations is:
->api('/me/friends?fields=name,location);
Which works fine for current location.
Any tips would be great. Thanks.
So it turns out the best way to do this is to use FQL against the "stream" table. From here we can add WHERE clauses to do exactly what I'm after. The hardest part is the lack of documentation provided by Facebook on a specific field. "Type".
https://developers.facebook.com/docs/reference/api/user/
https://developers.facebook.com/docs/reference/fql/stream/
Permissions required: "read_stream"
Doing the initial query "SELECT post_id, actor_id, target_id, message FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid=me() AND type='newsfeed') AND is_hidden = 0" gives you a wide list of updates within your news stream.
So by changing a few things on my test account I was able to find the "type"'s that matched the activity changes on a users account.
Work update - 305
Education update - 305
Work and Education are grouped.
Relationship status - 62
Changed locations - 282
So say if we wanted to be specific and look for one activity we can change the "type" to be equal to the id's mentioned above.
$query = "SELECT post_id, actor_id, target_id, message, created_time, description, description_tags, type, place FROM stream WHERE type = '62' filter_key in (SELECT filter_key FROM stream_filter WHERE uid=me())";
$response = $this->facebook->api('/fql?q=' . urlencode($query));
The response will look something like this:
'data' => array(
(int) 0 => array(
'post_id' => '100035395_38758242', //I've changed this post id to be random
'actor_id' => (int) 4242, //I've changed this actor_id to be random
'target_id' => null,
'message' => '',
'created_time' => (int) 1347601178,
'description' => 'Joe Smith updated his work and education on his timeline.',
'description_tags' => array(
(int) 0 => array(
(int) 0 => array(
'id' => (int) 4242, //I've changed this id to be random
'name' => 'Joe Smith',
'offset' => (int) 0,
'length' => (int) 8,
'type' => 'user'
)
)
),
'type' => (int) 305, //<--- Note the type id
'place' => null
),
);
Now we need to be aware that Education and Work history can be combined, and potentially other types can be as well. We can from here query the "post_id" directly to get more information related to it.
$post = $this->facebook->api('/100035395_38758242');
The response of this could be something like:
array(
'id' => '100035395_38758242',
'from' => array(
'name' => 'Joe Smith',
'id' => '4242'
),
'story' => 'Joe Smith added Harvid University of America to his timeline.',
'story_tags' => array(
(int) 0 => array(
(int) 0 => array(
'id' => '4242',
'name' => 'Joe Smith',
'offset' => (int) 0,
'length' => (int) 8,
'type' => 'user'
)
)
),
'actions' => array(
(int) 0 => array(
'name' => 'Comment',
'link' => 'http://www.facebook.com/3535/posts/345345' //Changed
),
(int) 1 => array(
'name' => 'Like',
'link' => 'http://www.facebook.com/345345/posts/34534' //Changed
)
),
'type' => 'link',
'created_time' => '2012-09-14T05:39:38+0000',
'updated_time' => '2012-09-14T05:39:38+0000',
'comments' => array(
'count' => (int) 0
)
)
The alternative could be to also query the user id directly and pull fields relevant to the "type". I.e. 'work' or 'education'.
$friend = $this->facebook->api('/242?fields=work,name,education,id');
NOTE: If you require data from X Weeks or Months ago you should use the "created_time" within your queries to Facebook, otherwise you're limited to: 30 days or 50 posts per query.