Get list of post by specific position in query - wordpress

I need create a loop with specifics post but I would like do it by position (not by id) of all of them. I want to use a single loop with specific position.
Example: (2, 5, 9, etc)
I tried to use wp_query methods but my php knowledge is little.

Outside the loop, create a counter variable:
$post_number = 1;
Then, while you're in the loop, you can check on the contents of the variable to see which post you are at. For instance, in the following example, only the first and second posts will be shown.
Just before you end the loop, add to the counter using $post_number++.
// Start loop
if ($post_number == 1 || $post_number == 2){
// standard loop contents ( the_title(), the_content(), etc)
}
$post_number++;
// stop loop

Why you not try inside a loop for an example:
if ($idpost == "4")
{
// print...
}

Related

How to apply SetFilter in a query object in while loop body after query.open() in AL Business Central

I just want to apply another filter while we are in the body of query during reading it.
For Example: Here is my code.
customAttributeQuery.SetFilter(Value_ID, attributeValueID);
customAttributeQuery.Open();
while customAttributeQuery.Read() do begin
counter := 0;
// HERE IN BODY I WANT TO APPLY ANOTHER FILTER
// customAttributeQuery.SetFilter(Value, attributeValue);
end;
The issue is when i apply another filter in the body of while loop and open the query and try to read it .This code always breaks my whole code.
I'm pretty sure you cannot do that, if you apply a filter, most probably you break the loop and jump out. Try to incorporate your filter inside the Query Object if possible, to that extent you can use something like:
Table 1 as t1
{
Table 2 a t2
{
Table 1 as t3
{}
}
}
if you use this correctly, by setting a filter on t2, you get your desired filter on t3, which is pointing to the Table in the t1 loop.

Function for Google Sheets' Script editor with a button for TODAY(), and NOW() in two different columns of which are the next not blank in the column

Currently, I'm looking at some simple documentation for vague ways to make a 'button' (image) over a Google sheet to trigger a function on the script editor. I'm not familiar with this type of Syntax, I typically do AutoHotKey, and a bit of python.
All I want to do is have this button populate 2 columns. The current date in one, and the current time in the other (It doesn't even have to have its year or the seconds tbh). I don't know if it matters of what the pages name is based on how the script works. So the range is ( 'Log'!G4:H ).
Like if I were to make it for AutoHotkey I would put it as :
WinGet, winid ,, A ; <-- need to identify window A = active
MsgBox, winid=%winid%
;do some stuff
WinActivate ahk_id %winid%
So it affects any page it's active on.
I would like to use the same function on the same columns across different sheets. Ideally, that is. I don't care if I have to clone each a unique function based on the page, but I just can't even grasp this first step, lol.
I'm not too familiar with this new macro. If I use this macro does it only work for my client, because of say like it recording relative aspect ratio movements?
IE if I record a macro on my PC, and play it on my android. Will the change in the platform change its execution?
If anyone can point me in any direction as to any good documentation or resources for the Google Sheet Script Editor or its syntaxes I would really appreciate it.
EDIT: Just to clarify. Im really focused in on it being a function that populates from a click/press(mobile) of an image. I currently use an onEDIT on the sheet, and it wouldnt serve the purposes that I want for this function. Its just a shortcut to quickly input a timestamp, and those fields can still be retouched without it just reapplying a new function for a newer current time/date.
EDIT:EDIT: Ended up with a image button that runs a script that can only input to the current cell.
function timeStamp() {
SpreadsheetApp.getActiveSheet()
.getActiveCell()
.setValue(new Date());
}
It only works on the cell targeted.
I would like to force the input in the next availible cell in the column, and split the date from the time, and put them into cells adjacent from one another.
maybe this will help... if the 1st column is edited it will auto-print date in 2nd column and time in 3rd column on Sheet1:
function onEdit(e) {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "Sheet1" ) {
var r = s.getActiveCell();
if( r.getColumn() == 1 ) {
var nextCell = r.offset(0, 1);
var newDate = Utilities.formatDate(new Date(),
"GMT+8", "MM/dd/yyyy");
nextCell.setValue(newDate);
}
if( r.getColumn() == 1 ) {
var nextCell = r.offset(0, 2);
var newDate1 = Utilities.formatDate(new Date(),
"GMT+8", "hh:mm:ss");
nextCell.setValue(newDate1);
}}}
https://webapps.stackexchange.com/a/130253/186471

R: Iterating Over the List

I am trying to implement following algorithm in R:
Iterate(Cell: top)
While (top != null)
Print top.Value
top = top.Next
End While
End Iterate
Basically, given a list, the algorithm should break as soon as it hits 'null' even when the list is not over.
myls<-list('africa','america south','asia','antarctica','australasia',NULL,'europe','america north')
I had to add a for loop for using is.null() function, but following code is disaster and I need your help to fix it.
Cell <- function(top) {
#This algorithm examines every cell in the linked list, so if the list contains N cells,
#it has run time O(N).
for (i in 1:length(top)){
while(is.null(top[[i]]) !=TRUE){
print(top)
top = next(top)
}
}
}
You may run this function using:
Cell(myls)
You were close but there is no need to use for(...) in this
construction.
Cell <- function(top){
i = 1
while(i <= length(top) && !is.null(top[[i]])){
print(top[[i]])
i = i + 1
}
}
As you see I've added one extra condition to the while loop: i <= length(top) this is to make sure you don't go beyond the length of the
list in case there no null items.
However you can use a for loop with this construction:
Cell <- function(top){
for(i in 1:length(top)){
if(is.null(top[[i]])) break
print(top[[i]])
}
}
Alternatively you can use this code without a for/while construction:
myls[1:(which(sapply(myls, is.null))[1]-1)]
Check this out: It runs one by one for all the values in myls and prints them but If it encounters NULL value it breaks.
for (val in myls) {
if (is.null(val)){
break
}
print(val)
}
Let me know in case of any query.

Remove item from groovy list

I am trying to remove an item from groovy list. I've tried following:
List<User> availableUsers = []
availableUsers = workers
for (int i = 0; i < availableUsers.size(); i++) {
if (availableUsers[i].equals(user)){
availableUsers.drop(i)
break
}
}
I've also tried:
availableUsers.remove(user)
In both cases the list gets emptied. Does anyone have any idea what's going on?
Have you tried
availableUsers - user
?
Docu: http://groovy.codehaus.org/groovy-jdk/java/util/List.html#minus(java.lang.Object)
Haven't got much experience with groovy myself, but that's what I would try.
As mentioned above, the answer depends on whether you wish to remove all occurrences of an item...
myList = ['a','b','c', 'c']
myList -= 'c'
assert myList == ['a','b']
...or just the first instance.
myList = ['a','b','c', 'c']
myList.remove(myList.indexOf('c'))
assert myList == ['a','b','c']
I'm still new to Groovy myself, but one of the underlying principles is that it almost always has a way of making common tasks trivial one-liners. Adding or removing items from a collection would certainly qualify.
Fildor is right, but if you only want ot remove the first occurence of user in your list (minus will remove all occurrences), you will probably need something like:
list = list.indexOf( user ).with { idx ->
if( idx > -1 ) {
new ArrayList( list ).with { a ->
a.remove( idx )
a
}
}
else list
}
I had a related requirement but wanted to remove more than one items knowing their index position. It was not easy to do in a loop as after removing the first item, the index position of the remaining ones changes. It seemed easy to first create a list with items to be removed and then use the collections minus operation to remove them from the target list. Here is an example:
myList=['a','b','c','d']
remove=[0,1,2] //index list of list elements to remove
removeList=myList[remove]
println removeList
assert ['d']== myList.minus(removeList)
LIMITATION:if the value at index is present multiple times in target list, ALL instances are removed.
So, if
myList=['a','b','c','d','a','e']
remove=[0,1,2]
removeList=myList[remove]
assert myList.minus(removeList)== ['d','e']
the result will be d,e

Flex mobile - How do I move to the next data in List.selectedItem when moving to next page?

When I move page01 to page02, I pass the same data along with it using the following code:
navigator.pushView(Page02, data);
How do I move to page02 with passing the next row of data (instead of the same data)?
In other word, how to increment to the next row of data with pushView?
Thanks.
If you have access to the List component which displays the data you want to pass into views, you can do something like this:
myList.dataProvider[myList.selectedIndex+1]
You'll want to do some checking to make sure that you're trying to reference an index that actually exists:
var mySelectedObject :Object;
if(myList.selectedIndex+1 < myList.dataProvider.length){
mySelectedObject = myList.dataProvider[myList.selectedIndex+1]
} else {
// do some other behaviour; such as selecting the first one in the list
mySelectedObject = myList.dataProvider[0]
}
navigator.pushView(page02, mySelectedObject );

Resources